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

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

Issue 2705273002: Throttle Socket watcher RTT notifications from QUIC (Closed)
Patch Set: Created 3 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
« no previous file with comments | « net/quic/chromium/quic_connection_logger.cc ('k') | net/socket/tcp_socket_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 5 #include <memory>
6 #include <ostream> 6 #include <ostream>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 was_proxied_ = true; 147 was_proxied_ = true;
148 } 148 }
149 149
150 private: 150 private:
151 bool was_proxied_; 151 bool was_proxied_;
152 }; 152 };
153 153
154 class TestSocketPerformanceWatcher : public SocketPerformanceWatcher { 154 class TestSocketPerformanceWatcher : public SocketPerformanceWatcher {
155 public: 155 public:
156 explicit TestSocketPerformanceWatcher(bool* rtt_notification_received) 156 TestSocketPerformanceWatcher(bool* should_notify_updated_rtt,
157 : rtt_notification_received_(rtt_notification_received) {} 157 bool* rtt_notification_received)
158 : should_notify_updated_rtt_(should_notify_updated_rtt),
159 rtt_notification_received_(rtt_notification_received) {}
158 ~TestSocketPerformanceWatcher() override {} 160 ~TestSocketPerformanceWatcher() override {}
159 161
160 bool ShouldNotifyUpdatedRTT() const override { return true; } 162 bool ShouldNotifyUpdatedRTT() const override {
163 return *should_notify_updated_rtt_;
164 }
161 165
162 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) override { 166 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) override {
163 *rtt_notification_received_ = true; 167 *rtt_notification_received_ = true;
164 } 168 }
165 169
166 void OnConnectionChanged() override {} 170 void OnConnectionChanged() override {}
167 171
168 private: 172 private:
173 bool* should_notify_updated_rtt_;
169 bool* rtt_notification_received_; 174 bool* rtt_notification_received_;
170 175
171 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcher); 176 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcher);
172 }; 177 };
173 178
174 class TestSocketPerformanceWatcherFactory 179 class TestSocketPerformanceWatcherFactory
175 : public SocketPerformanceWatcherFactory { 180 : public SocketPerformanceWatcherFactory {
176 public: 181 public:
177 TestSocketPerformanceWatcherFactory() 182 TestSocketPerformanceWatcherFactory()
178 : watcher_count_(0u), rtt_notification_received_(false) {} 183 : watcher_count_(0u),
184 should_notify_updated_rtt_(true),
185 rtt_notification_received_(false) {}
179 ~TestSocketPerformanceWatcherFactory() override {} 186 ~TestSocketPerformanceWatcherFactory() override {}
180 187
181 // SocketPerformanceWatcherFactory implementation: 188 // SocketPerformanceWatcherFactory implementation:
182 std::unique_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( 189 std::unique_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher(
183 const Protocol protocol) override { 190 const Protocol protocol) override {
184 if (protocol != PROTOCOL_QUIC) { 191 if (protocol != PROTOCOL_QUIC) {
185 return nullptr; 192 return nullptr;
186 } 193 }
187 ++watcher_count_; 194 ++watcher_count_;
188 return std::unique_ptr<SocketPerformanceWatcher>( 195 return std::unique_ptr<SocketPerformanceWatcher>(
189 new TestSocketPerformanceWatcher(&rtt_notification_received_)); 196 new TestSocketPerformanceWatcher(&should_notify_updated_rtt_,
197 &rtt_notification_received_));
190 } 198 }
191 199
192 size_t watcher_count() const { return watcher_count_; } 200 size_t watcher_count() const { return watcher_count_; }
193 201
194 bool rtt_notification_received() const { return rtt_notification_received_; } 202 bool rtt_notification_received() const { return rtt_notification_received_; }
195 203
204 void set_should_notify_updated_rtt(bool should_notify_updated_rtt) {
205 should_notify_updated_rtt_ = should_notify_updated_rtt;
206 }
207
196 private: 208 private:
197 size_t watcher_count_; 209 size_t watcher_count_;
210 bool should_notify_updated_rtt_;
198 bool rtt_notification_received_; 211 bool rtt_notification_received_;
199 212
200 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory); 213 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory);
201 }; 214 };
202 215
203 class QuicNetworkTransactionTest 216 class QuicNetworkTransactionTest
204 : public PlatformTest, 217 : public PlatformTest,
205 public ::testing::WithParamInterface<QuicVersion> { 218 public ::testing::WithParamInterface<QuicVersion> {
206 protected: 219 protected:
207 QuicNetworkTransactionTest() 220 QuicNetworkTransactionTest()
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } else { 759 } else {
747 EXPECT_TRUE(trans.GetResponseInfo()->proxy_server.is_direct()); 760 EXPECT_TRUE(trans.GetResponseInfo()->proxy_server.is_direct());
748 } 761 }
749 } 762 }
750 }; 763 };
751 764
752 INSTANTIATE_TEST_CASE_P(Version, 765 INSTANTIATE_TEST_CASE_P(Version,
753 QuicNetworkTransactionTest, 766 QuicNetworkTransactionTest,
754 ::testing::ValuesIn(AllSupportedVersions())); 767 ::testing::ValuesIn(AllSupportedVersions()));
755 768
756 TEST_P(QuicNetworkTransactionTest, ForceQuic) { 769 TEST_P(QuicNetworkTransactionTest, SocketWatcherEnabled) {
757 params_.origins_to_force_quic_on.insert( 770 params_.origins_to_force_quic_on.insert(
758 HostPortPair::FromString("mail.example.org:443")); 771 HostPortPair::FromString("mail.example.org:443"));
759 772
760 MockQuicData mock_quic_data; 773 MockQuicData mock_quic_data;
761 QuicStreamOffset header_stream_offset = 0; 774 QuicStreamOffset header_stream_offset = 0;
762 mock_quic_data.AddWrite(ConstructSettingsPacket( 775 mock_quic_data.AddWrite(ConstructSettingsPacket(
763 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, 776 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize,
764 &header_stream_offset)); 777 &header_stream_offset));
765 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 778 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
766 2, kClientDataStreamId1, true, true, 779 2, kClientDataStreamId1, true, true,
767 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); 780 GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
768 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( 781 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
769 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); 782 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK")));
770 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1, 783 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1,
771 false, true, 0, "hello!")); 784 false, true, 0, "hello!"));
772 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1)); 785 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1));
773 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read 786 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read
774 787
775 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 788 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
776 789
777 CreateSession(); 790 CreateSession();
791 test_socket_performance_watcher_factory_.set_should_notify_updated_rtt(true);
778 792
779 EXPECT_FALSE( 793 EXPECT_FALSE(
780 test_socket_performance_watcher_factory_.rtt_notification_received()); 794 test_socket_performance_watcher_factory_.rtt_notification_received());
781 SendRequestAndExpectQuicResponse("hello!"); 795 SendRequestAndExpectQuicResponse("hello!");
782 EXPECT_TRUE( 796 EXPECT_TRUE(
783 test_socket_performance_watcher_factory_.rtt_notification_received()); 797 test_socket_performance_watcher_factory_.rtt_notification_received());
798 }
799
800 TEST_P(QuicNetworkTransactionTest, SocketWatcherDisabled) {
801 params_.origins_to_force_quic_on.insert(
802 HostPortPair::FromString("mail.example.org:443"));
803
804 MockQuicData mock_quic_data;
805 QuicStreamOffset header_stream_offset = 0;
806 mock_quic_data.AddWrite(ConstructSettingsPacket(
807 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize,
808 &header_stream_offset));
809 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
810 2, kClientDataStreamId1, true, true,
811 GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
812 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
813 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK")));
814 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1,
815 false, true, 0, "hello!"));
816 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1));
817 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read
818
819 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
820
821 CreateSession();
822 test_socket_performance_watcher_factory_.set_should_notify_updated_rtt(false);
823
824 EXPECT_FALSE(
825 test_socket_performance_watcher_factory_.rtt_notification_received());
826 SendRequestAndExpectQuicResponse("hello!");
827 EXPECT_FALSE(
828 test_socket_performance_watcher_factory_.rtt_notification_received());
829 }
830
831 TEST_P(QuicNetworkTransactionTest, ForceQuic) {
832 params_.origins_to_force_quic_on.insert(
833 HostPortPair::FromString("mail.example.org:443"));
834
835 MockQuicData mock_quic_data;
836 QuicStreamOffset header_stream_offset = 0;
837 mock_quic_data.AddWrite(ConstructSettingsPacket(
838 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize,
839 &header_stream_offset));
840 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
841 2, kClientDataStreamId1, true, true,
842 GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
843 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
844 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK")));
845 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1,
846 false, true, 0, "hello!"));
847 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1));
848 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read
849
850 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
851
852 CreateSession();
853
854 SendRequestAndExpectQuicResponse("hello!");
784 855
785 // Check that the NetLog was filled reasonably. 856 // Check that the NetLog was filled reasonably.
786 TestNetLogEntry::List entries; 857 TestNetLogEntry::List entries;
787 net_log_.GetEntries(&entries); 858 net_log_.GetEntries(&entries);
788 EXPECT_LT(0u, entries.size()); 859 EXPECT_LT(0u, entries.size());
789 860
790 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. 861 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED.
791 int pos = ExpectLogContainsSomewhere( 862 int pos = ExpectLogContainsSomewhere(
792 entries, 0, NetLogEventType::QUIC_SESSION_PACKET_RECEIVED, 863 entries, 0, NetLogEventType::QUIC_SESSION_PACKET_RECEIVED,
793 NetLogEventPhase::NONE); 864 NetLogEventPhase::NONE);
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 AddHangingSocketData(); 3507 AddHangingSocketData();
3437 3508
3438 SendRequestAndExpectQuicResponse(origin1_); 3509 SendRequestAndExpectQuicResponse(origin1_);
3439 SendRequestAndExpectQuicResponse(origin2_); 3510 SendRequestAndExpectQuicResponse(origin2_);
3440 3511
3441 EXPECT_TRUE(AllDataConsumed()); 3512 EXPECT_TRUE(AllDataConsumed());
3442 } 3513 }
3443 3514
3444 } // namespace test 3515 } // namespace test
3445 } // namespace net 3516 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_connection_logger.cc ('k') | net/socket/tcp_socket_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698