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