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