Chromium Code Reviews| 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 <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 Loading... | |
| 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 explicit TestSocketPerformanceWatcher(bool* should_notify_updated_rtt, |
|
Ryan Hamilton
2017/02/15 23:08:16
nit: no need for explicit now that there are 2 arg
| |
| 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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 } else { | 760 } else { |
| 748 EXPECT_TRUE(trans.GetResponseInfo()->proxy_server.is_direct()); | 761 EXPECT_TRUE(trans.GetResponseInfo()->proxy_server.is_direct()); |
| 749 } | 762 } |
| 750 } | 763 } |
| 751 }; | 764 }; |
| 752 | 765 |
| 753 INSTANTIATE_TEST_CASE_P(Version, | 766 INSTANTIATE_TEST_CASE_P(Version, |
| 754 QuicNetworkTransactionTest, | 767 QuicNetworkTransactionTest, |
| 755 ::testing::ValuesIn(AllSupportedVersions())); | 768 ::testing::ValuesIn(AllSupportedVersions())); |
| 756 | 769 |
| 757 TEST_P(QuicNetworkTransactionTest, ForceQuic) { | 770 TEST_P(QuicNetworkTransactionTest, SocketWatcherEnabled) { |
| 758 params_.origins_to_force_quic_on.insert( | 771 params_.origins_to_force_quic_on.insert( |
| 759 HostPortPair::FromString("mail.example.org:443")); | 772 HostPortPair::FromString("mail.example.org:443")); |
| 760 | 773 |
| 761 MockQuicData mock_quic_data; | 774 MockQuicData mock_quic_data; |
| 762 QuicStreamOffset header_stream_offset = 0; | 775 QuicStreamOffset header_stream_offset = 0; |
| 763 mock_quic_data.AddWrite(ConstructSettingsPacket( | 776 mock_quic_data.AddWrite(ConstructSettingsPacket( |
| 764 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, | 777 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, |
| 765 &header_stream_offset)); | 778 &header_stream_offset)); |
| 766 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | 779 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 767 2, kClientDataStreamId1, true, true, | 780 2, kClientDataStreamId1, true, true, |
| 768 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); | 781 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); |
| 769 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | 782 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( |
| 770 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 783 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 771 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1, | 784 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1, |
| 772 false, true, 0, "hello!")); | 785 false, true, 0, "hello!")); |
| 773 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1)); | 786 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1)); |
| 774 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read | 787 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read |
| 775 | 788 |
| 776 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 789 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 777 | 790 |
| 778 CreateSession(); | 791 CreateSession(); |
| 792 test_socket_performance_watcher_factory_.set_should_notify_updated_rtt(true); | |
| 779 | 793 |
| 780 EXPECT_FALSE( | 794 EXPECT_FALSE( |
| 781 test_socket_performance_watcher_factory_.rtt_notification_received()); | 795 test_socket_performance_watcher_factory_.rtt_notification_received()); |
| 782 SendRequestAndExpectQuicResponse("hello!"); | 796 SendRequestAndExpectQuicResponse("hello!"); |
| 783 EXPECT_TRUE( | 797 EXPECT_TRUE( |
| 784 test_socket_performance_watcher_factory_.rtt_notification_received()); | 798 test_socket_performance_watcher_factory_.rtt_notification_received()); |
| 799 } | |
| 800 | |
| 801 TEST_P(QuicNetworkTransactionTest, SocketWatcherDisabled) { | |
| 802 params_.origins_to_force_quic_on.insert( | |
| 803 HostPortPair::FromString("mail.example.org:443")); | |
| 804 | |
| 805 MockQuicData mock_quic_data; | |
| 806 QuicStreamOffset header_stream_offset = 0; | |
| 807 mock_quic_data.AddWrite(ConstructSettingsPacket( | |
| 808 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, | |
| 809 &header_stream_offset)); | |
| 810 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
| 811 2, kClientDataStreamId1, true, true, | |
| 812 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); | |
| 813 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 814 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | |
| 815 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1, | |
| 816 false, true, 0, "hello!")); | |
| 817 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1)); | |
| 818 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read | |
| 819 | |
| 820 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | |
| 821 | |
| 822 CreateSession(); | |
| 823 test_socket_performance_watcher_factory_.set_should_notify_updated_rtt(false); | |
| 824 | |
| 825 EXPECT_FALSE( | |
| 826 test_socket_performance_watcher_factory_.rtt_notification_received()); | |
| 827 SendRequestAndExpectQuicResponse("hello!"); | |
| 828 EXPECT_FALSE( | |
| 829 test_socket_performance_watcher_factory_.rtt_notification_received()); | |
| 830 } | |
| 831 | |
| 832 TEST_P(QuicNetworkTransactionTest, ForceQuic) { | |
| 833 params_.origins_to_force_quic_on.insert( | |
| 834 HostPortPair::FromString("mail.example.org:443")); | |
| 835 | |
| 836 MockQuicData mock_quic_data; | |
| 837 QuicStreamOffset header_stream_offset = 0; | |
| 838 mock_quic_data.AddWrite(ConstructSettingsPacket( | |
| 839 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, | |
| 840 &header_stream_offset)); | |
| 841 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
| 842 2, kClientDataStreamId1, true, true, | |
| 843 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); | |
| 844 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 845 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | |
| 846 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1, | |
| 847 false, true, 0, "hello!")); | |
| 848 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1)); | |
| 849 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more data to read | |
| 850 | |
| 851 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | |
| 852 | |
| 853 CreateSession(); | |
| 854 | |
| 855 SendRequestAndExpectQuicResponse("hello!"); | |
| 785 | 856 |
| 786 // Check that the NetLog was filled reasonably. | 857 // Check that the NetLog was filled reasonably. |
| 787 TestNetLogEntry::List entries; | 858 TestNetLogEntry::List entries; |
| 788 net_log_.GetEntries(&entries); | 859 net_log_.GetEntries(&entries); |
| 789 EXPECT_LT(0u, entries.size()); | 860 EXPECT_LT(0u, entries.size()); |
| 790 | 861 |
| 791 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. | 862 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
| 792 int pos = ExpectLogContainsSomewhere( | 863 int pos = ExpectLogContainsSomewhere( |
| 793 entries, 0, NetLogEventType::QUIC_SESSION_PACKET_RECEIVED, | 864 entries, 0, NetLogEventType::QUIC_SESSION_PACKET_RECEIVED, |
| 794 NetLogEventPhase::NONE); | 865 NetLogEventPhase::NONE); |
| (...skipping 2641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |