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