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 "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
10 #include "net/cert/cert_verifier.h" | 10 #include "net/cert/cert_verifier.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 static void SetEnableConnectionRacing(QuicStreamFactory* factory, | 128 static void SetEnableConnectionRacing(QuicStreamFactory* factory, |
129 bool enable_connection_racing) { | 129 bool enable_connection_racing) { |
130 factory->enable_connection_racing_ = enable_connection_racing; | 130 factory->enable_connection_racing_ = enable_connection_racing; |
131 } | 131 } |
132 | 132 |
133 static void SetDisableDiskCache(QuicStreamFactory* factory, | 133 static void SetDisableDiskCache(QuicStreamFactory* factory, |
134 bool disable_disk_cache) { | 134 bool disable_disk_cache) { |
135 factory->disable_disk_cache_ = disable_disk_cache; | 135 factory->disable_disk_cache_ = disable_disk_cache; |
136 } | 136 } |
137 | 137 |
| 138 static bool GetQuicIsDisabled(QuicStreamFactory* factory) { |
| 139 return factory->quic_is_disabled_; |
| 140 } |
| 141 |
138 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory, | 142 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory, |
139 const QuicServerId& server_id) { | 143 const QuicServerId& server_id) { |
140 return (factory->active_jobs_[server_id]).size(); | 144 return (factory->active_jobs_[server_id]).size(); |
141 } | 145 } |
142 }; | 146 }; |
143 | 147 |
144 class MockQuicServerInfo : public QuicServerInfo { | 148 class MockQuicServerInfo : public QuicServerInfo { |
145 public: | 149 public: |
146 MockQuicServerInfo(const QuicServerId& server_id) | 150 MockQuicServerInfo(const QuicServerId& server_id) |
147 : QuicServerInfo(server_id) {} | 151 : QuicServerInfo(server_id) {} |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 kDefaultMaxPacketSize, | 203 kDefaultMaxPacketSize, |
200 std::string(), | 204 std::string(), |
201 SupportedVersions(GetParam().version), | 205 SupportedVersions(GetParam().version), |
202 /*enable_port_selection=*/true, | 206 /*enable_port_selection=*/true, |
203 /*always_require_handshake_confirmation=*/false, | 207 /*always_require_handshake_confirmation=*/false, |
204 /*disable_connection_pooling=*/false, | 208 /*disable_connection_pooling=*/false, |
205 /*load_server_info_timeout_srtt_multiplier=*/0.0f, | 209 /*load_server_info_timeout_srtt_multiplier=*/0.0f, |
206 /*enable_connection_racing=*/false, | 210 /*enable_connection_racing=*/false, |
207 /*enable_non_blocking_io=*/true, | 211 /*enable_non_blocking_io=*/true, |
208 /*disable_disk_cache=*/false, | 212 /*disable_disk_cache=*/false, |
| 213 /*max_number_of_lossy_connections=*/0, |
| 214 /*packet_loss_threshold=*/1000.0f, |
209 /*receive_buffer_size=*/0, | 215 /*receive_buffer_size=*/0, |
210 QuicTagVector()), | 216 QuicTagVector()), |
211 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), | 217 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
212 is_https_(false), | 218 is_https_(false), |
213 privacy_mode_(PRIVACY_MODE_DISABLED) { | 219 privacy_mode_(PRIVACY_MODE_DISABLED) { |
214 factory_.set_require_confirmation(false); | 220 factory_.set_require_confirmation(false); |
215 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 221 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
216 QuicStreamFactoryPeer::SetEnableConnectionRacing( | 222 QuicStreamFactoryPeer::SetEnableConnectionRacing( |
217 &factory_, GetParam().enable_connection_racing); | 223 &factory_, GetParam().enable_connection_racing); |
218 } | 224 } |
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 // If we are waiting for disk cache, we would have posted a task. Verify that | 1680 // If we are waiting for disk cache, we would have posted a task. Verify that |
1675 // the CancelWaitForDataReady task hasn't been posted. | 1681 // the CancelWaitForDataReady task hasn't been posted. |
1676 ASSERT_EQ(0u, runner_->GetPostedTasks().size()); | 1682 ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
1677 | 1683 |
1678 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 1684 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
1679 EXPECT_TRUE(stream.get()); | 1685 EXPECT_TRUE(stream.get()); |
1680 EXPECT_TRUE(socket_data.at_read_eof()); | 1686 EXPECT_TRUE(socket_data.at_read_eof()); |
1681 EXPECT_TRUE(socket_data.at_write_eof()); | 1687 EXPECT_TRUE(socket_data.at_write_eof()); |
1682 } | 1688 } |
1683 | 1689 |
| 1690 TEST_P(QuicStreamFactoryTest, BadPacketLoss) { |
| 1691 factory_.set_quic_server_info_factory(&quic_server_info_factory_); |
| 1692 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get()); |
| 1693 EXPECT_FALSE(QuicStreamFactoryPeer::GetQuicIsDisabled(&factory_)); |
| 1694 |
| 1695 // OnBadPacketLoss should disable QUIC. |
| 1696 QuicServerId server_id(host_port_pair_, is_https_, privacy_mode_); |
| 1697 factory_.OnBadPacketLoss(server_id); |
| 1698 EXPECT_TRUE(QuicStreamFactoryPeer::GetQuicIsDisabled(&factory_)); |
| 1699 |
| 1700 QuicStreamRequest request(&factory_); |
| 1701 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 1702 request.Request(host_port_pair_, is_https_, privacy_mode_, "GET", |
| 1703 net_log_, callback_.callback())); |
| 1704 } |
| 1705 |
1684 } // namespace test | 1706 } // namespace test |
1685 } // namespace net | 1707 } // namespace net |
OLD | NEW |