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 ffd19182b53a8668766cab7988031ff9a92c49e7..11938238644ddb33e2b73b7d69fc55b678726f89 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/socket_performance_watcher.h" |
+#include "net/base/socket_performance_watcher_factory.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,73 @@ 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); |
+}; |
+ |
+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 TestSocketPerformanceWatcherFactory |
+ : public SocketPerformanceWatcherFactory { |
+ public: |
+ TestSocketPerformanceWatcherFactory() |
+ : watcher_notification_verifier_(new WatcherNotificationVerifier()) {} |
+ |
+ ~TestSocketPerformanceWatcherFactory() override {} |
+ |
+ scoped_ptr<SocketPerformanceWatcher> CreateUDPSocketPerformanceWatcher() |
+ const override { |
+ return scoped_ptr<TestSocketPerformanceWatcher>( |
+ new TestSocketPerformanceWatcher(watcher_notification_verifier_.get())); |
+ } |
+ |
+ scoped_ptr<SocketPerformanceWatcher> CreateTCPSocketPerformanceWatcher() |
+ const override { |
+ return scoped_ptr<SocketPerformanceWatcher>( |
+ new TestSocketPerformanceWatcher(nullptr)); |
+ } |
+ |
+ bool IsRTTAvailableRTTNotificationReceived() const { |
+ return watcher_notification_verifier_ |
+ ->IsRTTAvailableRTTNotificationReceived(); |
+ } |
+ |
+ private: |
+ scoped_ptr<WatcherNotificationVerifier> watcher_notification_verifier_; |
+ DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory); |
+}; |
+ |
class QuicNetworkTransactionTest |
: public PlatformTest, |
public ::testing::WithParamInterface<QuicVersion> { |
@@ -146,6 +215,8 @@ class QuicNetworkTransactionTest |
QuicNetworkTransactionTest() |
: clock_(new MockClock), |
maker_(GetParam(), 0, clock_, kDefaultServerHostName), |
+ socket_performance_watcher_factory_( |
+ new TestSocketPerformanceWatcherFactory()), |
ssl_config_service_(new SSLConfigServiceDefaults), |
proxy_service_(ProxyService::CreateDirect()), |
auth_handler_factory_( |
@@ -248,6 +319,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 = |
+ socket_performance_watcher_factory_.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 +445,8 @@ class QuicNetworkTransactionTest |
MockHostResolver host_resolver_; |
MockCertVerifier cert_verifier_; |
TransportSecurityState transport_security_state_; |
+ scoped_ptr<TestSocketPerformanceWatcherFactory> |
+ socket_performance_watcher_factory_; |
scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
scoped_ptr<ProxyService> proxy_service_; |
scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
@@ -492,12 +567,16 @@ TEST_P(QuicNetworkTransactionTest, QuicProxy) { |
mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
+ DCHECK(!socket_performance_watcher_factory_ |
+ ->IsRTTAvailableRTTNotificationReceived()); |
// 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); |
+ DCHECK(socket_performance_watcher_factory_ |
+ ->IsRTTAvailableRTTNotificationReceived()); |
} |
// Regression test for https://crbug.com/492458. Test that for an HTTP |
@@ -542,6 +621,8 @@ TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
CreateSessionWithNextProtos(); |
AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
+ DCHECK(socket_performance_watcher_factory_ |
Ryan Hamilton
2015/09/17 01:59:49
s/DCHECK/EXPECT_TRUE/ ?
tbansal1
2015/09/17 22:23:42
Done.
|
+ ->IsRTTAvailableRTTNotificationReceived()); |
} |
TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
@@ -584,6 +665,8 @@ TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
CreateSession(); |
SendRequestAndExpectHttpResponse("hello world"); |
+ DCHECK(!socket_performance_watcher_factory_ |
+ ->IsRTTAvailableRTTNotificationReceived()); |
} |
TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuic) { |
@@ -1488,6 +1571,8 @@ TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
SendRequestAndExpectHttpResponse("hello from http"); |
ExpectBrokenAlternateProtocolMapping(); |
+ DCHECK(socket_performance_watcher_factory_ |
+ ->IsRTTAvailableRTTNotificationReceived()); |
} |
TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
@@ -1517,6 +1602,8 @@ TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
SendRequestAndExpectHttpResponse("hello from http"); |
ExpectBrokenAlternateProtocolMapping(); |
+ DCHECK(!socket_performance_watcher_factory_ |
+ ->IsRTTAvailableRTTNotificationReceived()); |
} |
TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { |