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