[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/quic/quic_stream_factory.h" |
| 6 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 7 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 8 | #include "base/strings/string_util.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 9 | #include "net/base/test_data_directory.h" |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 10 | #include "net/cert/cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 11 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 12 | #include "net/http/http_response_headers.h" |
| 13 | #include "net/http/http_response_info.h" |
| 14 | #include "net/http/http_util.h" |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 15 | #include "net/quic/crypto/crypto_handshake.h" |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 16 | #include "net/quic/crypto/proof_verifier_chromium.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 17 | #include "net/quic/crypto/quic_decrypter.h" |
| 18 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 19 | #include "net/quic/quic_http_stream.h" |
[email protected] | 8b9a6039 | 2014-03-12 10:05:42 | [diff] [blame] | 20 | #include "net/quic/quic_session_key.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 21 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 22 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 23 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 24 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 25 | #include "net/quic/test_tools/quic_test_utils.h" |
| 26 | #include "net/socket/socket_test_util.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 27 | #include "net/test/cert_test_util.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 28 | #include "testing/gtest/include/gtest/gtest.h" |
| 29 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 30 | using base::StringPiece; |
| 31 | using std::string; |
| 32 | using std::vector; |
| 33 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 34 | namespace net { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 35 | namespace test { |
| 36 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 37 | namespace { |
| 38 | const char kDefaultServerHostName[] = "www.google.com"; |
| 39 | const int kDefaultServerPort = 443; |
| 40 | } // namespace anonymous |
| 41 | |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 42 | class QuicStreamFactoryPeer { |
| 43 | public: |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 44 | static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { |
| 45 | return &factory->crypto_config_; |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 46 | } |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 47 | |
| 48 | static bool HasActiveSession(QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 49 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 50 | bool is_https) { |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 51 | QuicSessionKey server_key(host_port_pair, is_https); |
| 52 | return factory->HasActiveSession(server_key); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static QuicClientSession* GetActiveSession( |
| 56 | QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 57 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 58 | bool is_https) { |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 59 | QuicSessionKey server_key(host_port_pair, is_https); |
| 60 | DCHECK(factory->HasActiveSession(server_key)); |
| 61 | return factory->active_sessions_[server_key]; |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
| 65 | QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 66 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 67 | bool is_https, |
| 68 | const BoundNetLog& net_log) { |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 69 | QuicSessionKey server_key(host_port_pair, is_https); |
| 70 | return factory->CreateIfSessionExists(server_key, net_log); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static bool IsLiveSession(QuicStreamFactory* factory, |
| 74 | QuicClientSession* session) { |
| 75 | for (QuicStreamFactory::SessionSet::iterator it = |
| 76 | factory->all_sessions_.begin(); |
| 77 | it != factory->all_sessions_.end(); ++it) { |
| 78 | if (*it == session) |
| 79 | return true; |
| 80 | } |
| 81 | return false; |
| 82 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 83 | }; |
| 84 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 85 | class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 86 | protected: |
| 87 | QuicStreamFactoryTest() |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 88 | : random_generator_(0), |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 89 | maker_(GetParam(), 0), |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 90 | clock_(new MockClock()), |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 91 | cert_verifier_(CertVerifier::CreateDefault()), |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 92 | factory_(&host_resolver_, &socket_factory_, |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 93 | base::WeakPtr<HttpServerProperties>(), |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 94 | cert_verifier_.get(), |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 95 | &crypto_client_stream_factory_, |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 96 | &random_generator_, clock_, kDefaultMaxPacketSize, |
[email protected] | c80f7c9 | 2014-02-27 13:12:02 | [diff] [blame] | 97 | SupportedVersions(GetParam()), true, true), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 98 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 99 | is_https_(false) { |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 100 | factory_.set_require_confirmation(false); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 103 | scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 104 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 105 | const BoundNetLog& net_log) { |
| 106 | return QuicStreamFactoryPeer::CreateIfSessionExists( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 107 | &factory_, host_port_pair, false, net_log_); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 108 | } |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 109 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 110 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 111 | return GetSourcePortForNewSessionInner(destination, false); |
| 112 | } |
| 113 | |
| 114 | int GetSourcePortForNewSessionAndGoAway( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 115 | const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 116 | return GetSourcePortForNewSessionInner(destination, true); |
| 117 | } |
| 118 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 119 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 120 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 121 | // Should only be called if there is no active session for this destination. |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 122 | EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 123 | size_t socket_count = socket_factory_.udp_client_sockets().size(); |
| 124 | |
| 125 | MockRead reads[] = { |
| 126 | MockRead(ASYNC, OK, 0) // EOF |
| 127 | }; |
| 128 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 129 | socket_data.StopAfter(1); |
| 130 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 131 | |
| 132 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 133 | EXPECT_EQ(ERR_IO_PENDING, |
| 134 | request.Request(destination, |
| 135 | is_https_, |
| 136 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 137 | net_log_, |
| 138 | callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 139 | |
| 140 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 141 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 142 | EXPECT_TRUE(stream.get()); |
| 143 | stream.reset(); |
| 144 | |
| 145 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 146 | &factory_, destination, is_https_); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 147 | |
| 148 | if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { |
| 149 | EXPECT_TRUE(false); |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | IPEndPoint endpoint; |
| 154 | socket_factory_. |
| 155 | udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); |
| 156 | int port = endpoint.port(); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 157 | if (goaway_received) { |
| 158 | QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, ""); |
| 159 | session->OnGoAway(goaway); |
| 160 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 161 | |
| 162 | factory_.OnSessionClosed(session); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 163 | EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 164 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 165 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 166 | return port; |
| 167 | } |
| 168 | |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 169 | scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 170 | QuicStreamId stream_id = 5; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 171 | return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR); |
| 172 | } |
| 173 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 174 | MockHostResolver host_resolver_; |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 175 | DeterministicMockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 176 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 177 | MockRandom random_generator_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 178 | QuicTestPacketMaker maker_; |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 179 | MockClock* clock_; // Owned by factory_. |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 180 | scoped_ptr<CertVerifier> cert_verifier_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 181 | QuicStreamFactory factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 182 | HostPortPair host_port_pair_; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 183 | bool is_https_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 184 | BoundNetLog net_log_; |
| 185 | TestCompletionCallback callback_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 186 | }; |
| 187 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 188 | INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, |
| 189 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 190 | |
| 191 | TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 192 | EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 195 | TEST_P(QuicStreamFactoryTest, Create) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 196 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 197 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 198 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 199 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 200 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 201 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 202 | |
| 203 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 204 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 205 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 206 | is_https_, |
| 207 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 208 | net_log_, |
| 209 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 210 | |
| 211 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 212 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 213 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 214 | |
| 215 | // Will reset stream 3. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 216 | stream = CreateIfSessionExists(host_port_pair_, net_log_); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 217 | EXPECT_TRUE(stream.get()); |
| 218 | |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 219 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 220 | // in streams on different sessions. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 221 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 222 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 223 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 224 | is_https_, |
| 225 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 226 | net_log_, |
| 227 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 228 | stream = request2.ReleaseStream(); // Will reset stream 5. |
| 229 | stream.reset(); // Will reset stream 7. |
| 230 | |
| 231 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 232 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 233 | } |
| 234 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 235 | TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) { |
| 236 | MockRead reads[] = { |
| 237 | MockRead(ASYNC, OK, 0) // EOF |
| 238 | }; |
| 239 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 240 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 241 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 242 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 243 | socket_data1.StopAfter(1); |
| 244 | socket_data2.StopAfter(1); |
| 245 | |
| 246 | QuicStreamRequest request(&factory_); |
| 247 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 248 | request.Request(host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 249 | is_https_, |
| 250 | "GET", |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 251 | net_log_, |
| 252 | callback_.callback())); |
| 253 | |
| 254 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 255 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 256 | EXPECT_TRUE(stream.get()); |
| 257 | |
| 258 | QuicStreamRequest request2(&factory_); |
| 259 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 260 | request2.Request(host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 261 | !is_https_, |
| 262 | "GET", |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 263 | net_log_, |
| 264 | callback_.callback())); |
| 265 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 266 | stream = request2.ReleaseStream(); |
| 267 | EXPECT_TRUE(stream.get()); |
| 268 | stream.reset(); |
| 269 | |
| 270 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 271 | &factory_, host_port_pair_, is_https_), |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 272 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 273 | &factory_, host_port_pair_, !is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 274 | |
| 275 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 276 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 277 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 278 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 279 | } |
| 280 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 281 | TEST_P(QuicStreamFactoryTest, Pooling) { |
| 282 | MockRead reads[] = { |
| 283 | MockRead(ASYNC, OK, 0) // EOF |
| 284 | }; |
| 285 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 286 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 287 | socket_data.StopAfter(1); |
| 288 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 289 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 290 | host_resolver_.set_synchronous_mode(true); |
| 291 | host_resolver_.rules()->AddIPLiteralRule( |
| 292 | kDefaultServerHostName, "192.168.0.1", ""); |
| 293 | host_resolver_.rules()->AddIPLiteralRule( |
| 294 | "mail.google.com", "192.168.0.1", ""); |
| 295 | |
| 296 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 297 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 298 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 299 | is_https_, |
| 300 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 301 | net_log_, |
| 302 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 303 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 304 | EXPECT_TRUE(stream.get()); |
| 305 | |
| 306 | TestCompletionCallback callback; |
| 307 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 308 | EXPECT_EQ(OK, |
| 309 | request2.Request(server2, |
| 310 | is_https_, |
| 311 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 312 | net_log_, |
| 313 | callback.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 314 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 315 | EXPECT_TRUE(stream2.get()); |
| 316 | |
| 317 | EXPECT_EQ( |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 318 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 319 | &factory_, host_port_pair_, is_https_), |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 320 | QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 321 | |
| 322 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 323 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 324 | } |
| 325 | |
| 326 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
| 327 | MockRead reads[] = { |
| 328 | MockRead(ASYNC, OK, 0) // EOF |
| 329 | }; |
| 330 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 331 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 332 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 333 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 334 | socket_data1.StopAfter(1); |
| 335 | socket_data2.StopAfter(1); |
| 336 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 337 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 338 | host_resolver_.set_synchronous_mode(true); |
| 339 | host_resolver_.rules()->AddIPLiteralRule( |
| 340 | kDefaultServerHostName, "192.168.0.1", ""); |
| 341 | host_resolver_.rules()->AddIPLiteralRule( |
| 342 | "mail.google.com", "192.168.0.1", ""); |
| 343 | |
| 344 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 345 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 346 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 347 | is_https_, |
| 348 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 349 | net_log_, |
| 350 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 351 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 352 | EXPECT_TRUE(stream.get()); |
| 353 | |
| 354 | TestCompletionCallback callback; |
| 355 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 356 | EXPECT_EQ(OK, |
| 357 | request2.Request(server2, |
| 358 | is_https_, |
| 359 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 360 | net_log_, |
| 361 | callback.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 362 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 363 | EXPECT_TRUE(stream2.get()); |
| 364 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 365 | factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 366 | &factory_, host_port_pair_, is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 367 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 368 | &factory_, host_port_pair_, is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 369 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
| 370 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 371 | |
| 372 | TestCompletionCallback callback3; |
| 373 | QuicStreamRequest request3(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 374 | EXPECT_EQ(OK, |
| 375 | request3.Request(server2, |
| 376 | is_https_, |
| 377 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 378 | net_log_, |
| 379 | callback3.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 380 | scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); |
| 381 | EXPECT_TRUE(stream3.get()); |
| 382 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 383 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( |
| 384 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 385 | |
| 386 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 387 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 388 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 389 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 390 | } |
| 391 | |
| 392 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
| 393 | MockRead reads[] = { |
| 394 | MockRead(ASYNC, OK, 0) // EOF |
| 395 | }; |
| 396 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 397 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 398 | socket_data.StopAfter(1); |
| 399 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 400 | HostPortPair server1("www.example.org", 443); |
| 401 | HostPortPair server2("mail.example.org", 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 402 | |
| 403 | // Load a cert that is valid for: |
| 404 | // www.example.org (server1) |
| 405 | // mail.example.org (server2) |
| 406 | // www.example.com |
| 407 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 408 | scoped_refptr<X509Certificate> test_cert( |
| 409 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 410 | ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 411 | ProofVerifyDetailsChromium verify_details; |
| 412 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 413 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 414 | |
| 415 | host_resolver_.set_synchronous_mode(true); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 416 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 417 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 418 | |
| 419 | QuicStreamRequest request(&factory_); |
| 420 | is_https_ = true; |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 421 | EXPECT_EQ(OK, |
| 422 | request.Request(server1, |
| 423 | is_https_, |
| 424 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 425 | net_log_, |
| 426 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 427 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 428 | EXPECT_TRUE(stream.get()); |
| 429 | |
| 430 | TestCompletionCallback callback; |
| 431 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 432 | EXPECT_EQ(OK, |
| 433 | request2.Request(server2, |
| 434 | is_https_, |
| 435 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 436 | net_log_, |
| 437 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 438 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 439 | EXPECT_TRUE(stream2.get()); |
| 440 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 441 | EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
| 442 | &factory_, server1, is_https_), |
| 443 | QuicStreamFactoryPeer::GetActiveSession( |
| 444 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 445 | |
| 446 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 447 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 448 | } |
| 449 | |
| 450 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { |
| 451 | MockRead reads[] = { |
| 452 | MockRead(ASYNC, OK, 0) // EOF |
| 453 | }; |
| 454 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 455 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 456 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 457 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 458 | socket_data1.StopAfter(1); |
| 459 | socket_data2.StopAfter(1); |
| 460 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 461 | HostPortPair server1("www.example.org", 443); |
| 462 | HostPortPair server2("mail.google.com", 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 463 | |
| 464 | // Load a cert that is valid for: |
| 465 | // www.example.org (server1) |
| 466 | // mail.example.org |
| 467 | // www.example.com |
| 468 | // But is not valid for mail.google.com (server2). |
| 469 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 470 | scoped_refptr<X509Certificate> test_cert( |
| 471 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 472 | ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 473 | ProofVerifyDetailsChromium verify_details; |
| 474 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 475 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 476 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 477 | |
| 478 | host_resolver_.set_synchronous_mode(true); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 479 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 480 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 481 | |
| 482 | QuicStreamRequest request(&factory_); |
| 483 | is_https_ = true; |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 484 | EXPECT_EQ(OK, |
| 485 | request.Request(server1, |
| 486 | is_https_, |
| 487 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 488 | net_log_, |
| 489 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 490 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 491 | EXPECT_TRUE(stream.get()); |
| 492 | |
| 493 | TestCompletionCallback callback; |
| 494 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 495 | EXPECT_EQ(OK, |
| 496 | request2.Request(server2, |
| 497 | is_https_, |
| 498 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 499 | net_log_, |
| 500 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 501 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 502 | EXPECT_TRUE(stream2.get()); |
| 503 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 504 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 505 | &factory_, server1, is_https_), |
| 506 | QuicStreamFactoryPeer::GetActiveSession( |
| 507 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 508 | |
| 509 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 510 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 511 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 512 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 513 | } |
| 514 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 515 | TEST_P(QuicStreamFactoryTest, Goaway) { |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 516 | MockRead reads[] = { |
| 517 | MockRead(ASYNC, OK, 0) // EOF |
| 518 | }; |
| 519 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 520 | socket_data.StopAfter(1); |
| 521 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 522 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 523 | socket_data2.StopAfter(1); |
| 524 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 525 | |
| 526 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 527 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 528 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 529 | is_https_, |
| 530 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 531 | net_log_, |
| 532 | callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 533 | |
| 534 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 535 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 536 | EXPECT_TRUE(stream.get()); |
| 537 | |
| 538 | // Mark the session as going away. Ensure that while it is still alive |
| 539 | // that it is no longer active. |
| 540 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 541 | &factory_, host_port_pair_, is_https_); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 542 | factory_.OnSessionGoingAway(session); |
| 543 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 544 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 545 | &factory_, host_port_pair_, is_https_)); |
| 546 | EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 547 | |
| 548 | // Create a new request for the same destination and verify that a |
| 549 | // new session is created. |
| 550 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 551 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 552 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 553 | is_https_, |
| 554 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 555 | net_log_, |
| 556 | callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 557 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 558 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 559 | EXPECT_TRUE(stream2.get()); |
| 560 | |
| 561 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 562 | host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 563 | is_https_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 564 | EXPECT_NE(session, |
| 565 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 566 | &factory_, host_port_pair_, is_https_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 567 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 568 | |
| 569 | stream2.reset(); |
| 570 | stream.reset(); |
| 571 | |
| 572 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 573 | EXPECT_TRUE(socket_data.at_write_eof()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 574 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 575 | EXPECT_TRUE(socket_data2.at_write_eof()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 576 | } |
| 577 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 578 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 579 | MockRead reads[] = { |
| 580 | MockRead(ASYNC, OK, 0) // EOF |
| 581 | }; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 582 | QuicStreamId stream_id = 5; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 583 | scoped_ptr<QuicEncryptedPacket> rst( |
| 584 | maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED)); |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 585 | MockWrite writes[] = { |
| 586 | MockWrite(ASYNC, rst->data(), rst->length(), 1), |
| 587 | }; |
| 588 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 589 | writes, arraysize(writes)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 590 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 591 | socket_data.StopAfter(1); |
| 592 | |
| 593 | HttpRequestInfo request_info; |
| 594 | std::vector<QuicHttpStream*> streams; |
| 595 | // The MockCryptoClientStream sets max_open_streams to be |
| 596 | // 2 * kDefaultMaxStreamsPerConnection. |
| 597 | for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { |
| 598 | QuicStreamRequest request(&factory_); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 599 | int rv = request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 600 | is_https_, |
| 601 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 602 | net_log_, |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 603 | callback_.callback()); |
| 604 | if (i == 0) { |
| 605 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 606 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 607 | } else { |
| 608 | EXPECT_EQ(OK, rv); |
| 609 | } |
| 610 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 611 | EXPECT_TRUE(stream); |
| 612 | EXPECT_EQ(OK, stream->InitializeStream( |
| 613 | &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); |
| 614 | streams.push_back(stream.release()); |
| 615 | } |
| 616 | |
| 617 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 618 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 619 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 620 | is_https_, |
| 621 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 622 | net_log_, |
| 623 | CompletionCallback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 624 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 625 | EXPECT_TRUE(stream); |
| 626 | EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( |
| 627 | &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); |
| 628 | |
| 629 | // Close the first stream. |
| 630 | streams.front()->Close(false); |
| 631 | |
| 632 | ASSERT_TRUE(callback_.have_result()); |
| 633 | |
| 634 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 635 | |
| 636 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 637 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 638 | STLDeleteElements(&streams); |
| 639 | } |
| 640 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 641 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 642 | DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 643 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 644 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 645 | host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 646 | |
| 647 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 648 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 649 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 650 | is_https_, |
| 651 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 652 | net_log_, |
| 653 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 654 | |
| 655 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 656 | |
| 657 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 658 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 659 | } |
| 660 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 661 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 662 | MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 663 | DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
| 664 | socket_data.set_connect_data(connect); |
| 665 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 666 | socket_data.StopAfter(1); |
| 667 | |
| 668 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 669 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 670 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 671 | is_https_, |
| 672 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 673 | net_log_, |
| 674 | callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 675 | |
| 676 | EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); |
| 677 | |
| 678 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 679 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 680 | } |
| 681 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 682 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 683 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 684 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 685 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 686 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 687 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 688 | { |
| 689 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 690 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 691 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 692 | is_https_, |
| 693 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 694 | net_log_, |
| 695 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 696 | } |
| 697 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 698 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 699 | base::RunLoop run_loop; |
| 700 | run_loop.RunUntilIdle(); |
| 701 | |
| 702 | scoped_ptr<QuicHttpStream> stream( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 703 | CreateIfSessionExists(host_port_pair_, net_log_)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 704 | EXPECT_TRUE(stream.get()); |
| 705 | stream.reset(); |
| 706 | |
| 707 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 708 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 709 | } |
| 710 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 711 | TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 712 | // Sequentially connect to the default host, then another host, and then the |
| 713 | // default host. Verify that the default host gets a consistent ephemeral |
| 714 | // port, that is different from the other host's connection. |
| 715 | |
| 716 | std::string other_server_name = "other.google.com"; |
| 717 | EXPECT_NE(kDefaultServerHostName, other_server_name); |
| 718 | HostPortPair host_port_pair2(other_server_name, kDefaultServerPort); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 719 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 720 | int original_port = GetSourcePortForNewSession(host_port_pair_); |
| 721 | EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair2)); |
| 722 | EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 723 | } |
| 724 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 725 | TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) { |
| 726 | // Get a session to the host using the port suggester. |
| 727 | int original_port = |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 728 | GetSourcePortForNewSessionAndGoAway(host_port_pair_); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 729 | // Verify that the port is different after the goaway. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 730 | EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 731 | // Since the previous session did not goaway we should see the original port. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 732 | EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 733 | } |
| 734 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 735 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 736 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 737 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 738 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 739 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 740 | std::vector<MockWrite> writes; |
| 741 | if (GetParam() > QUIC_VERSION_13) |
| 742 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
| 743 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 744 | writes.empty() ? NULL : &writes[0], |
| 745 | writes.size()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 746 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 747 | socket_data.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 748 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 749 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 750 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 751 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 752 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 753 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 754 | socket_data2.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 755 | |
| 756 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 757 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 758 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 759 | is_https_, |
| 760 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 761 | net_log_, |
| 762 | callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 763 | |
| 764 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 765 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 766 | HttpRequestInfo request_info; |
| 767 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 768 | DEFAULT_PRIORITY, |
| 769 | net_log_, CompletionCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 770 | |
| 771 | // Close the session and verify that stream saw the error. |
| 772 | factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); |
| 773 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 774 | stream->ReadResponseHeaders(callback_.callback())); |
| 775 | |
| 776 | // Now attempting to request a stream to the same origin should create |
| 777 | // a new session. |
| 778 | |
| 779 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 780 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 781 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 782 | is_https_, |
| 783 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 784 | net_log_, |
| 785 | callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 786 | |
| 787 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 788 | stream = request2.ReleaseStream(); |
| 789 | stream.reset(); // Will reset stream 3. |
| 790 | |
| 791 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 792 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 793 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 794 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 795 | } |
| 796 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 797 | TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) { |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 798 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 799 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 800 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 801 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 802 | std::vector<MockWrite> writes; |
| 803 | if (GetParam() > QUIC_VERSION_13) |
| 804 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
| 805 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 806 | writes.empty() ? NULL : &writes[0], |
| 807 | writes.size()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 808 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 809 | socket_data.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 810 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 811 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 812 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 813 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 814 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 815 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 816 | socket_data2.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 817 | |
| 818 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 819 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 820 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 821 | is_https_, |
| 822 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 823 | net_log_, |
| 824 | callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 825 | |
| 826 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 827 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 828 | HttpRequestInfo request_info; |
| 829 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 830 | DEFAULT_PRIORITY, |
| 831 | net_log_, CompletionCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 832 | |
| 833 | // Change the IP address and verify that stream saw the error. |
| 834 | factory_.OnIPAddressChanged(); |
| 835 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 836 | stream->ReadResponseHeaders(callback_.callback())); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 837 | EXPECT_TRUE(factory_.require_confirmation()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 838 | |
| 839 | // Now attempting to request a stream to the same origin should create |
| 840 | // a new session. |
| 841 | |
| 842 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 843 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 844 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 845 | is_https_, |
| 846 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 847 | net_log_, |
| 848 | callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 849 | |
| 850 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 851 | stream = request2.ReleaseStream(); |
| 852 | stream.reset(); // Will reset stream 3. |
| 853 | |
| 854 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 855 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 856 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 857 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 858 | } |
| 859 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 860 | TEST_P(QuicStreamFactoryTest, OnCertAdded) { |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 861 | MockRead reads[] = { |
| 862 | MockRead(ASYNC, 0, 0) // EOF |
| 863 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 864 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 865 | std::vector<MockWrite> writes; |
| 866 | if (GetParam() > QUIC_VERSION_13) |
| 867 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
| 868 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 869 | writes.empty() ? NULL : &writes[0], |
| 870 | writes.size()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 871 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 872 | socket_data.StopAfter(1); |
| 873 | |
| 874 | MockRead reads2[] = { |
| 875 | MockRead(ASYNC, 0, 0) // EOF |
| 876 | }; |
| 877 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
| 878 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 879 | socket_data2.StopAfter(1); |
| 880 | |
| 881 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 882 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 883 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 884 | is_https_, |
| 885 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 886 | net_log_, |
| 887 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 888 | |
| 889 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 890 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 891 | HttpRequestInfo request_info; |
| 892 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 893 | DEFAULT_PRIORITY, |
| 894 | net_log_, CompletionCallback())); |
| 895 | |
| 896 | // Add a cert and verify that stream saw the event. |
| 897 | factory_.OnCertAdded(NULL); |
| 898 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 899 | stream->ReadResponseHeaders(callback_.callback())); |
| 900 | EXPECT_FALSE(factory_.require_confirmation()); |
| 901 | |
| 902 | // Now attempting to request a stream to the same origin should create |
| 903 | // a new session. |
| 904 | |
| 905 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 906 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 907 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 908 | is_https_, |
| 909 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 910 | net_log_, |
| 911 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 912 | |
| 913 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 914 | stream = request2.ReleaseStream(); |
| 915 | stream.reset(); // Will reset stream 3. |
| 916 | |
| 917 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 918 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 919 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 920 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 921 | } |
| 922 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 923 | TEST_P(QuicStreamFactoryTest, OnCACertChanged) { |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 924 | MockRead reads[] = { |
| 925 | MockRead(ASYNC, 0, 0) // EOF |
| 926 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 927 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 928 | std::vector<MockWrite> writes; |
| 929 | if (GetParam() > QUIC_VERSION_13) |
| 930 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
| 931 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 932 | writes.empty() ? NULL : &writes[0], |
| 933 | writes.size()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 934 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 935 | socket_data.StopAfter(1); |
| 936 | |
| 937 | MockRead reads2[] = { |
| 938 | MockRead(ASYNC, 0, 0) // EOF |
| 939 | }; |
| 940 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
| 941 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 942 | socket_data2.StopAfter(1); |
| 943 | |
| 944 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 945 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 946 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 947 | is_https_, |
| 948 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 949 | net_log_, |
| 950 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 951 | |
| 952 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 953 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 954 | HttpRequestInfo request_info; |
| 955 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 956 | DEFAULT_PRIORITY, |
| 957 | net_log_, CompletionCallback())); |
| 958 | |
| 959 | // Change the CA cert and verify that stream saw the event. |
| 960 | factory_.OnCACertChanged(NULL); |
| 961 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 962 | stream->ReadResponseHeaders(callback_.callback())); |
| 963 | EXPECT_FALSE(factory_.require_confirmation()); |
| 964 | |
| 965 | // Now attempting to request a stream to the same origin should create |
| 966 | // a new session. |
| 967 | |
| 968 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 969 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 970 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 971 | is_https_, |
| 972 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 973 | net_log_, |
| 974 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 975 | |
| 976 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 977 | stream = request2.ReleaseStream(); |
| 978 | stream.reset(); // Will reset stream 3. |
| 979 | |
| 980 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 981 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 982 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 983 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 984 | } |
| 985 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 986 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 987 | vector<string> cannoncial_suffixes; |
| 988 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 989 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 990 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 991 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 992 | string r1_host_name("r1"); |
| 993 | string r2_host_name("r2"); |
| 994 | r1_host_name.append(cannoncial_suffixes[i]); |
| 995 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 996 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 997 | HostPortPair host_port_pair1(r1_host_name, 80); |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 998 | QuicCryptoClientConfig* crypto_config = |
| 999 | QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 1000 | QuicSessionKey server_key1(host_port_pair1, is_https_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1001 | QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 1002 | crypto_config->LookupOrCreate(server_key1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1003 | EXPECT_FALSE(cached1->proof_valid()); |
| 1004 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1005 | |
| 1006 | // Mutate the cached1 to have different data. |
| 1007 | // TODO(rtenneti): mutate other members of CachedState. |
| 1008 | cached1->set_source_address_token(r1_host_name); |
| 1009 | cached1->SetProofValid(); |
| 1010 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1011 | HostPortPair host_port_pair2(r2_host_name, 80); |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 1012 | QuicSessionKey server_key2(host_port_pair2, is_https_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1013 | QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 1014 | crypto_config->LookupOrCreate(server_key2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1015 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 1016 | EXPECT_TRUE(cached2->proof_valid()); |
| 1017 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1020 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1021 | vector<string> cannoncial_suffixes; |
| 1022 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1023 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1024 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1025 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1026 | string r3_host_name("r3"); |
| 1027 | string r4_host_name("r4"); |
| 1028 | r3_host_name.append(cannoncial_suffixes[i]); |
| 1029 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1030 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1031 | HostPortPair host_port_pair1(r3_host_name, 80); |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 1032 | QuicCryptoClientConfig* crypto_config = |
| 1033 | QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 1034 | QuicSessionKey server_key1(host_port_pair1, is_https_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1035 | QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 1036 | crypto_config->LookupOrCreate(server_key1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1037 | EXPECT_FALSE(cached1->proof_valid()); |
| 1038 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1039 | |
| 1040 | // Mutate the cached1 to have different data. |
| 1041 | // TODO(rtenneti): mutate other members of CachedState. |
| 1042 | cached1->set_source_address_token(r3_host_name); |
| 1043 | cached1->SetProofInvalid(); |
| 1044 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1045 | HostPortPair host_port_pair2(r4_host_name, 80); |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 1046 | QuicSessionKey server_key2(host_port_pair2, is_https_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1047 | QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame^] | 1048 | crypto_config->LookupOrCreate(server_key2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1049 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 1050 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 1051 | EXPECT_FALSE(cached2->proof_valid()); |
| 1052 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1055 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1056 | } // namespace net |