Chromium Code Reviews| Index: net/quic/quic_network_transaction_unittest.cc |
| diff --git a/net/quic/quic_network_transaction_unittest.cc b/net/quic/quic_network_transaction_unittest.cc |
| index b0b5de27f0abd90d32b3e42686ec88748e2aa5e0..59027b1d3e782356709d5a53f81b1f264be66fac 100644 |
| --- a/net/quic/quic_network_transaction_unittest.cc |
| +++ b/net/quic/quic_network_transaction_unittest.cc |
| @@ -8,6 +8,8 @@ |
| #include "base/compiler_specific.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/stl_util.h" |
| +#include "net/base/network_quality_estimator.h" |
| +#include "net/base/socket_performance_watcher.h" |
| #include "net/base/test_completion_callback.h" |
| #include "net/base/test_data_directory.h" |
| #include "net/cert/mock_cert_verifier.h" |
| @@ -139,6 +141,79 @@ class ProxyHeadersHandler { |
| bool was_called_; |
| }; |
| +// Verifies whether the socket performance watcher was notified of updated RTT. |
| +class WatcherNotificationVerifier { |
| + public: |
| + WatcherNotificationVerifier() |
| + : received_updated_rtt_available_notification_(false) {} |
| + |
| + virtual ~WatcherNotificationVerifier() {} |
| + |
| + void OnUpdatedRTTAvailable() { |
| + received_updated_rtt_available_notification_ = true; |
| + } |
| + |
| + bool IsRTTAvailableRTTNotificationReceived() const { |
| + return received_updated_rtt_available_notification_; |
| + } |
| + |
| + private: |
| + bool received_updated_rtt_available_notification_; |
| + DISALLOW_COPY_AND_ASSIGN(WatcherNotificationVerifier); |
| +}; |
|
Ryan Hamilton
2015/09/18 15:56:38
Instead of creating this class which exists simply
tbansal1
2015/09/18 17:21:20
Removed the class. I am not sure if EXPECT_TRUE(ha
|
| + |
| +class TestSocketPerformanceWatcher : public SocketPerformanceWatcher { |
| + public: |
| + TestSocketPerformanceWatcher(WatcherNotificationVerifier* watcher_checker) |
| + : watcher_notification_verifier_(watcher_checker) {} |
| + |
| + ~TestSocketPerformanceWatcher() override {} |
| + |
| + void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) override { |
| + watcher_notification_verifier_->OnUpdatedRTTAvailable(); |
| + } |
| + |
| + private: |
| + WatcherNotificationVerifier* watcher_notification_verifier_; |
| + DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcher); |
| +}; |
| + |
| +class TestNetworkQualityEstimator : public NetworkQualityEstimator { |
|
Ryan Hamilton
2015/09/18 15:56:38
Instead of a full blown NQE, how 'bout just a Soc
tbansal1
2015/09/18 17:21:20
Yeah, I had TestSocketPerformanceWatcherFactory be
Ryan Hamilton
2015/09/18 22:01:26
Are you actually testing any methods of the NQE be
tbansal1
2015/09/18 22:36:22
Not right now. That's because NQE is not doing any
|
| + public: |
| + TestNetworkQualityEstimator() |
| + : NetworkQualityEstimator(scoped_ptr<net::ExternalEstimateProvider>(), |
| + std::map<std::string, std::string>()), |
| + watcher_notification_verifier_(new WatcherNotificationVerifier()), |
| + watchers_created_(0) {} |
| + |
| + ~TestNetworkQualityEstimator() override {} |
| + |
| + scoped_ptr<SocketPerformanceWatcher> CreateUDPSocketPerformanceWatcher() |
| + const override { |
| + watchers_created_++; |
| + return scoped_ptr<TestSocketPerformanceWatcher>( |
| + new TestSocketPerformanceWatcher(watcher_notification_verifier_.get())); |
| + } |
| + |
| + scoped_ptr<SocketPerformanceWatcher> CreateTCPSocketPerformanceWatcher() |
| + const override { |
| + NOTIMPLEMENTED(); |
| + return scoped_ptr<SocketPerformanceWatcher>(); |
| + } |
| + |
| + bool IsRTTAvailableRTTNotificationReceived() const { |
| + return watcher_notification_verifier_ |
| + ->IsRTTAvailableRTTNotificationReceived(); |
| + } |
| + |
| + size_t GetWatchersCreated() const { return watchers_created_; } |
| + |
| + private: |
| + scoped_ptr<WatcherNotificationVerifier> watcher_notification_verifier_; |
| + mutable size_t watchers_created_; |
| + DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| +}; |
| + |
| class QuicNetworkTransactionTest |
| : public PlatformTest, |
| public ::testing::WithParamInterface<QuicVersion> { |
| @@ -146,6 +221,7 @@ class QuicNetworkTransactionTest |
| QuicNetworkTransactionTest() |
| : clock_(new MockClock), |
| maker_(GetParam(), 0, clock_, kDefaultServerHostName), |
| + test_network_quality_estimator_(new TestNetworkQualityEstimator()), |
| ssl_config_service_(new SSLConfigServiceDefaults), |
| proxy_service_(ProxyService::CreateDirect()), |
| auth_handler_factory_( |
| @@ -248,6 +324,8 @@ class QuicNetworkTransactionTest |
| params_.host_resolver = &host_resolver_; |
| params_.cert_verifier = &cert_verifier_; |
| params_.transport_security_state = &transport_security_state_; |
| + params_.socket_performance_watcher_factory = |
| + test_network_quality_estimator_.get(); |
| params_.proxy_service = proxy_service_.get(); |
| params_.ssl_config_service = ssl_config_service_.get(); |
| params_.http_auth_handler_factory = auth_handler_factory_.get(); |
| @@ -372,6 +450,7 @@ class QuicNetworkTransactionTest |
| MockHostResolver host_resolver_; |
| MockCertVerifier cert_verifier_; |
| TransportSecurityState transport_security_state_; |
| + scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; |
| scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| scoped_ptr<ProxyService> proxy_service_; |
| scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
| @@ -430,7 +509,13 @@ TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
| CreateSession(); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| SendRequestAndExpectQuicResponse("hello!"); |
| + EXPECT_TRUE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(1U, test_network_quality_estimator_->GetWatchersCreated()); |
| // Check that the NetLog was filled reasonably. |
| TestNetLogEntry::List entries; |
| @@ -491,12 +576,18 @@ TEST_P(QuicNetworkTransactionTest, QuicProxy) { |
| mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| // There is no need to set up an alternate protocol job, because |
| // no attempt will be made to speak to the proxy over TCP. |
| CreateSession(); |
| SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
| + EXPECT_TRUE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(1U, test_network_quality_estimator_->GetWatchersCreated()); |
| } |
| // Regression test for https://crbug.com/492458. Test that for an HTTP |
| @@ -540,7 +631,13 @@ TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
| AddHangingNonAlternateProtocolSocketData(); |
| CreateSessionWithNextProtos(); |
| AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
| + EXPECT_TRUE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(1U, test_network_quality_estimator_->GetWatchersCreated()); |
| } |
| TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
| @@ -548,19 +645,27 @@ TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
| params_.origin_to_force_quic_on = |
| HostPortPair::FromString("www.google.com:80"); |
| - MockQuicData mock_quic_data; |
| - mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| + MockQuicData mock_quic_data1; |
| + mock_quic_data1.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| - mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| + MockQuicData mock_quic_data2; |
| + mock_quic_data2.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| + |
| + mock_quic_data1.AddSocketDataToFactory(&socket_factory_); |
| + mock_quic_data2.AddSocketDataToFactory(&socket_factory_); |
| CreateSession(); |
| - scoped_ptr<HttpNetworkTransaction> trans( |
| - new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| - TestCompletionCallback callback; |
| - int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| + for (size_t i = 0; i < 2; ++i) { |
| + scoped_ptr<HttpNetworkTransaction> trans( |
| + new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| + TestCompletionCallback callback; |
| + int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| + EXPECT_EQ(ERR_IO_PENDING, rv); |
| + EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
| + EXPECT_EQ(1 + i, test_network_quality_estimator_->GetWatchersCreated()); |
| + } |
| } |
| TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
| @@ -583,6 +688,9 @@ TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
| CreateSession(); |
| SendRequestAndExpectHttpResponse("hello world"); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| } |
| TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuic) { |
| @@ -1459,6 +1567,9 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
| TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
| params_.enable_insecure_quic = true; |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| // Alternate-protocol job |
| scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| MockRead quic_reads[] = { |
| @@ -1486,6 +1597,9 @@ TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
| AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| SendRequestAndExpectHttpResponse("hello from http"); |
| ExpectBrokenAlternateProtocolMapping(); |
| + EXPECT_TRUE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(1U, test_network_quality_estimator_->GetWatchersCreated()); |
| } |
| TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
| @@ -1513,8 +1627,14 @@ TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
| CreateSessionWithNextProtos(); |
| AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| SendRequestAndExpectHttpResponse("hello from http"); |
| ExpectBrokenAlternateProtocolMapping(); |
| + EXPECT_TRUE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(1U, test_network_quality_estimator_->GetWatchersCreated()); |
| } |
| TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { |
| @@ -1644,6 +1764,9 @@ TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { |
| SendRequestAndExpectHttpResponse("hello from http"); |
| ExpectBrokenAlternateProtocolMapping(); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| } |
| TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { |
| @@ -1721,6 +1844,9 @@ TEST_P(QuicNetworkTransactionTest, SecureResourceOverInsecureQuic) { |
| TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
| params_.enable_insecure_quic = true; |
| maker_.set_hostname("www.example.org"); |
| + EXPECT_FALSE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(0U, test_network_quality_estimator_->GetWatchersCreated()); |
| MockQuicData mock_quic_data; |
| mock_quic_data.AddWrite( |
| ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| @@ -1748,6 +1874,9 @@ TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
| CreateSessionWithNextProtos(); |
| AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| SendRequestAndExpectQuicResponse("hello!"); |
| + EXPECT_TRUE( |
| + test_network_quality_estimator_->IsRTTAvailableRTTNotificationReceived()); |
| + EXPECT_EQ(1U, test_network_quality_estimator_->GetWatchersCreated()); |
|
Ryan Hamilton
2015/09/18 15:56:38
I doesn't seem like we need to test this behavior
tbansal1
2015/09/18 17:21:20
Agreed. Removed some of the tests.
|
| } |
| } // namespace test |