[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 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/spdy/spdy_proxy_client_socket.h" |
| 6 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7 | #include "base/bind.h" |
| 8 | #include "base/bind_helpers.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame^] | 9 | #include "base/macros.h" |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 10 | #include "base/run_loop.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 12 | #include "net/base/address_list.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 13 | #include "net/base/test_completion_callback.h" |
| 14 | #include "net/base/winsock_init.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 15 | #include "net/dns/mock_host_resolver.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 16 | #include "net/http/http_response_headers.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 17 | #include "net/http/http_response_info.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 18 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 19 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 20 | #include "net/log/test_net_log_entry.h" |
| 21 | #include "net/log/test_net_log_util.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 22 | #include "net/socket/client_socket_factory.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 23 | #include "net/socket/next_proto.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 24 | #include "net/socket/socket_test_util.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 25 | #include "net/socket/tcp_client_socket.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 26 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 27 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 28 | #include "net/spdy/spdy_protocol.h" |
| 29 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 30 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 31 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 32 | #include "testing/platform_test.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 33 | |
| 34 | //----------------------------------------------------------------------------- |
| 35 | |
| 36 | namespace { |
| 37 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 38 | enum TestCase { |
| 39 | // Test using the SPDY/3.1 protocol. |
| 40 | kTestCaseSPDY31, |
| 41 | |
| 42 | // Test using the HTTP/2 protocol, without specifying a stream |
| 43 | // dependency based on the RequestPriority. |
| 44 | kTestCaseHTTP2NoPriorityDependencies, |
| 45 | |
| 46 | // Test using the HTTP/2 protocol, specifying a stream |
| 47 | // dependency based on the RequestPriority. |
| 48 | kTestCaseHTTP2PriorityDependencies |
| 49 | }; |
| 50 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 51 | static const char kRequestUrl[] = "https://www.google.com/"; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 52 | static const char kOriginHost[] = "www.google.com"; |
| 53 | static const int kOriginPort = 443; |
| 54 | static const char kOriginHostPort[] = "www.google.com:443"; |
[email protected] | e9fa548 | 2011-07-08 18:29:11 | [diff] [blame] | 55 | static const char kProxyUrl[] = "https://myproxy:6121/"; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 56 | static const char kProxyHost[] = "myproxy"; |
| 57 | static const int kProxyPort = 6121; |
| 58 | static const char kUserAgent[] = "Mozilla/1.0"; |
| 59 | |
| 60 | static const int kStreamId = 1; |
| 61 | |
| 62 | static const char kMsg1[] = "\0hello!\xff"; |
| 63 | static const int kLen1 = 8; |
[email protected] | b99ebde | 2014-07-08 23:41:04 | [diff] [blame] | 64 | static const char kMsg2[] = "\0a2345678\0"; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 65 | static const int kLen2 = 10; |
| 66 | static const char kMsg3[] = "bye!"; |
| 67 | static const int kLen3 = 4; |
| 68 | static const char kMsg33[] = "bye!bye!"; |
| 69 | static const int kLen33 = kLen3 + kLen3; |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 70 | static const char kMsg333[] = "bye!bye!bye!"; |
| 71 | static const int kLen333 = kLen3 + kLen3 + kLen3; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 72 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 73 | static const char kRedirectUrl[] = "https://example.com/"; |
| 74 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 75 | } // anonymous namespace |
| 76 | |
| 77 | namespace net { |
| 78 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 79 | class SpdyProxyClientSocketTest : public PlatformTest, |
| 80 | public testing::WithParamInterface<TestCase> { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 81 | public: |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 82 | SpdyProxyClientSocketTest(); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 83 | ~SpdyProxyClientSocketTest(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 84 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 85 | void TearDown() override; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 86 | |
| 87 | protected: |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 88 | NextProto GetProtocol() const; |
| 89 | bool GetDependenciesFromPriority() const; |
| 90 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 91 | void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, |
| 92 | size_t writes_count); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 93 | void PopulateConnectRequestIR(SpdyHeaderBlock* syn_ir); |
| 94 | void PopulateConnectReplyIR(SpdyHeaderBlock* block, const char* status); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 95 | SpdyFrame* ConstructConnectRequestFrame(); |
| 96 | SpdyFrame* ConstructConnectAuthRequestFrame(); |
| 97 | SpdyFrame* ConstructConnectReplyFrame(); |
| 98 | SpdyFrame* ConstructConnectAuthReplyFrame(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 99 | SpdyFrame* ConstructConnectRedirectReplyFrame(); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 100 | SpdyFrame* ConstructConnectErrorReplyFrame(); |
| 101 | SpdyFrame* ConstructBodyFrame(const char* data, int length); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 102 | scoped_refptr<IOBufferWithSize> CreateBuffer(const char* data, int size); |
| 103 | void AssertConnectSucceeds(); |
| 104 | void AssertConnectFails(int result); |
| 105 | void AssertConnectionEstablished(); |
| 106 | void AssertSyncReadEquals(const char* data, int len); |
| 107 | void AssertAsyncReadEquals(const char* data, int len); |
| 108 | void AssertReadStarts(const char* data, int len); |
| 109 | void AssertReadReturns(const char* data, int len); |
| 110 | void AssertAsyncWriteSucceeds(const char* data, int len); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 111 | void AssertWriteReturns(const char* data, int len, int rv); |
| 112 | void AssertWriteLength(int len); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 113 | |
| 114 | void AddAuthToCache() { |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 115 | const base::string16 kFoo(base::ASCIIToUTF16("foo")); |
| 116 | const base::string16 kBar(base::ASCIIToUTF16("bar")); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 117 | session_->http_auth_cache()->Add(GURL(kProxyUrl), |
| 118 | "MyRealm1", |
| 119 | HttpAuth::AUTH_SCHEME_BASIC, |
| 120 | "Basic realm=MyRealm1", |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 121 | AuthCredentials(kFoo, kBar), |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 122 | "/"); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 123 | } |
| 124 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 125 | void ResumeAndRun() { |
| 126 | // Run until the pause, if the provider isn't paused yet. |
| 127 | data_->RunUntilPaused(); |
| 128 | data_->Resume(); |
| 129 | base::RunLoop().RunUntilIdle(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 130 | } |
| 131 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 132 | void CloseSpdySession(Error error, const std::string& description) { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 133 | spdy_session_->CloseSessionOnError(error, description); |
| 134 | } |
| 135 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 136 | SpdyTestUtil spdy_util_; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 137 | scoped_ptr<SpdyProxyClientSocket> sock_; |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 138 | TestCompletionCallback read_callback_; |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 139 | TestCompletionCallback write_callback_; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 140 | scoped_ptr<SequencedSocketData> data_; |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 141 | BoundTestNetLog net_log_; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 142 | |
| 143 | private: |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 144 | scoped_ptr<HttpNetworkSession> session_; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 145 | scoped_refptr<IOBuffer> read_buf_; |
| 146 | SpdySessionDependencies session_deps_; |
| 147 | MockConnect connect_data_; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 148 | base::WeakPtr<SpdySession> spdy_session_; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 149 | BufferedSpdyFramer framer_; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 150 | |
| 151 | std::string user_agent_; |
| 152 | GURL url_; |
| 153 | HostPortPair proxy_host_port_; |
| 154 | HostPortPair endpoint_host_port_pair_; |
| 155 | ProxyServer proxy_; |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 156 | SpdySessionKey endpoint_spdy_session_key_; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 157 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 158 | DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 159 | }; |
| 160 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 161 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 162 | SpdyProxyClientSocketTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 163 | testing::Values(kTestCaseSPDY31, |
| 164 | kTestCaseHTTP2NoPriorityDependencies, |
| 165 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 166 | |
| 167 | SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 168 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 169 | read_buf_(NULL), |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 170 | session_deps_(GetProtocol()), |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 171 | connect_data_(SYNCHRONOUS, OK), |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 172 | framer_(spdy_util_.spdy_version(), false), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 173 | user_agent_(kUserAgent), |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 174 | url_(kRequestUrl), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 175 | proxy_host_port_(kProxyHost, kProxyPort), |
| 176 | endpoint_host_port_pair_(kOriginHost, kOriginPort), |
| 177 | proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), |
[email protected] | dd946bb | 2013-06-12 22:53:01 | [diff] [blame] | 178 | endpoint_spdy_session_key_(endpoint_host_port_pair_, |
| 179 | proxy_, |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 180 | PRIVACY_MODE_DISABLED) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 181 | session_deps_.net_log = net_log_.bound().net_log(); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 182 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 183 | GetDependenciesFromPriority()); |
| 184 | } |
| 185 | |
| 186 | SpdyProxyClientSocketTest::~SpdyProxyClientSocketTest() { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 187 | EXPECT_TRUE(data_->AllWriteDataConsumed()); |
| 188 | EXPECT_TRUE(data_->AllReadDataConsumed()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 189 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 192 | void SpdyProxyClientSocketTest::TearDown() { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 193 | if (session_.get() != NULL) |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 194 | session_->spdy_session_pool()->CloseAllSessions(); |
| 195 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 196 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 197 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 198 | PlatformTest::TearDown(); |
| 199 | } |
| 200 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 201 | NextProto SpdyProxyClientSocketTest::GetProtocol() const { |
| 202 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 203 | } |
| 204 | |
| 205 | bool SpdyProxyClientSocketTest::GetDependenciesFromPriority() const { |
| 206 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 207 | } |
| 208 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 209 | void SpdyProxyClientSocketTest::Initialize(MockRead* reads, |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 210 | size_t reads_count, |
| 211 | MockWrite* writes, |
| 212 | size_t writes_count) { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 213 | data_.reset( |
| 214 | new SequencedSocketData(reads, reads_count, writes, writes_count)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 215 | data_->set_connect_data(connect_data_); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 216 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 217 | session_deps_.socket_factory->AddSocketDataProvider(data_.get()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 218 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 219 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 220 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 221 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 222 | // Creates the SPDY session and stream. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 223 | spdy_session_ = CreateInsecureSpdySession( |
| 224 | session_.get(), endpoint_spdy_session_key_, BoundNetLog()); |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 225 | base::WeakPtr<SpdyStream> spdy_stream( |
| 226 | CreateStreamSynchronously( |
[email protected] | fb73cd67 | 2013-05-27 12:53:08 | [diff] [blame] | 227 | SPDY_BIDIRECTIONAL_STREAM, spdy_session_, url_, LOWEST, |
| 228 | net_log_.bound())); |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 229 | ASSERT_TRUE(spdy_stream.get() != NULL); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 230 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 231 | // Create the SpdyProxyClientSocket. |
rch | ecd3c55 | 2015-04-07 20:53:54 | [diff] [blame] | 232 | sock_.reset(new SpdyProxyClientSocket( |
| 233 | spdy_stream, user_agent_, endpoint_host_port_pair_, proxy_host_port_, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 234 | net_log_.bound(), |
| 235 | new HttpAuthController( |
| 236 | HttpAuth::AUTH_PROXY, GURL("https://" + proxy_host_port_.ToString()), |
| 237 | session_->http_auth_cache(), session_->http_auth_handler_factory()))); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 240 | scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 241 | const char* data, int size) { |
| 242 | scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); |
| 243 | memcpy(buf->data(), data, size); |
| 244 | return buf; |
| 245 | } |
| 246 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 247 | void SpdyProxyClientSocketTest::AssertConnectSucceeds() { |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 248 | ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 249 | ASSERT_EQ(OK, read_callback_.WaitForResult()); |
| 250 | } |
| 251 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 252 | void SpdyProxyClientSocketTest::AssertConnectFails(int result) { |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 253 | ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 254 | ASSERT_EQ(result, read_callback_.WaitForResult()); |
| 255 | } |
| 256 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 257 | void SpdyProxyClientSocketTest::AssertConnectionEstablished() { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 258 | const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
| 259 | ASSERT_TRUE(response != NULL); |
| 260 | ASSERT_EQ(200, response->headers->response_code()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 261 | } |
| 262 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 263 | void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data, |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 264 | int len) { |
| 265 | scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 266 | ASSERT_EQ(len, sock_->Read(buf.get(), len, CompletionCallback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 267 | ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); |
| 268 | ASSERT_TRUE(sock_->IsConnected()); |
| 269 | } |
| 270 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 271 | void SpdyProxyClientSocketTest::AssertAsyncReadEquals(const char* data, |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 272 | int len) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 273 | // Issue the read, which will be completed asynchronously |
| 274 | scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 275 | ASSERT_EQ(ERR_IO_PENDING, |
| 276 | sock_->Read(buf.get(), len, read_callback_.callback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 277 | EXPECT_TRUE(sock_->IsConnected()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 278 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 279 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 280 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 281 | EXPECT_EQ(len, read_callback_.WaitForResult()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 282 | EXPECT_TRUE(sock_->IsConnected()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 283 | ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); |
| 284 | } |
| 285 | |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 286 | void SpdyProxyClientSocketTest::AssertReadStarts(const char* data, int len) { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 287 | // Issue the read, which will be completed asynchronously. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 288 | read_buf_ = new IOBuffer(len); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 289 | ASSERT_EQ(ERR_IO_PENDING, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 290 | sock_->Read(read_buf_.get(), len, read_callback_.callback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 291 | EXPECT_TRUE(sock_->IsConnected()); |
| 292 | } |
| 293 | |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 294 | void SpdyProxyClientSocketTest::AssertReadReturns(const char* data, int len) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 295 | EXPECT_TRUE(sock_->IsConnected()); |
| 296 | |
| 297 | // Now the read will return |
| 298 | EXPECT_EQ(len, read_callback_.WaitForResult()); |
| 299 | ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len)); |
| 300 | } |
| 301 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 302 | void SpdyProxyClientSocketTest::AssertAsyncWriteSucceeds(const char* data, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 303 | int len) { |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 304 | AssertWriteReturns(data, len, ERR_IO_PENDING); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 305 | AssertWriteLength(len); |
| 306 | } |
| 307 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 308 | void SpdyProxyClientSocketTest::AssertWriteReturns(const char* data, |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 309 | int len, |
| 310 | int rv) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 311 | scoped_refptr<IOBufferWithSize> buf(CreateBuffer(data, len)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 312 | EXPECT_EQ(rv, |
| 313 | sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 314 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 315 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 316 | void SpdyProxyClientSocketTest::AssertWriteLength(int len) { |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 317 | EXPECT_EQ(len, write_callback_.WaitForResult()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 320 | void SpdyProxyClientSocketTest::PopulateConnectRequestIR( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 321 | SpdyHeaderBlock* block) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 322 | spdy_util_.MaybeAddVersionHeader(block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 323 | (*block)[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 324 | if (spdy_util_.spdy_version() == HTTP2) { |
| 325 | (*block)[spdy_util_.GetHostKey()] = kOriginHostPort; |
| 326 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 327 | (*block)[spdy_util_.GetHostKey()] = kOriginHost; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 328 | (*block)[spdy_util_.GetPathKey()] = kOriginHostPort; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 329 | } |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 330 | (*block)["user-agent"] = kUserAgent; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 331 | } |
| 332 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 333 | void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 334 | const char* status) { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 335 | (*block)[spdy_util_.GetStatusKey()] = status; |
| 336 | spdy_util_.MaybeAddVersionHeader(block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 339 | // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 340 | SpdyFrame* |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 341 | SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 342 | SpdyHeaderBlock block; |
| 343 | PopulateConnectRequestIR(&block); |
| 344 | return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false, false); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes |
| 348 | // Proxy-Authorization headers. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 349 | SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 350 | SpdyHeaderBlock block; |
| 351 | PopulateConnectRequestIR(&block); |
| 352 | block["proxy-authorization"] = "Basic Zm9vOmJhcg=="; |
| 353 | return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false, false); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 357 | SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 358 | SpdyHeaderBlock block; |
| 359 | PopulateConnectReplyIR(&block, "200"); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 360 | SpdySynReplyIR reply_ir(kStreamId); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 361 | return spdy_util_.ConstructSpdyReply(kStreamId, block); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 364 | // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, |
| 365 | // including Proxy-Authenticate headers. |
| 366 | SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 367 | SpdyHeaderBlock block; |
| 368 | PopulateConnectReplyIR(&block, "407"); |
| 369 | block["proxy-authenticate"] = "Basic realm=\"MyRealm1\""; |
| 370 | return spdy_util_.ConstructSpdyReply(kStreamId, block); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 373 | // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 374 | SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 375 | SpdyHeaderBlock block; |
| 376 | PopulateConnectReplyIR(&block, "302"); |
| 377 | block["location"] = kRedirectUrl; |
| 378 | block["set-cookie"] = "foo=bar"; |
| 379 | return spdy_util_.ConstructSpdyReply(kStreamId, block); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 380 | } |
| 381 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 382 | // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 383 | SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 384 | SpdyHeaderBlock block; |
| 385 | PopulateConnectReplyIR(&block, "500"); |
| 386 | return spdy_util_.ConstructSpdyReply(kStreamId, block); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 389 | SpdyFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( |
| 390 | const char* data, |
| 391 | int length) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 392 | return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // ----------- Connect |
| 396 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 397 | TEST_P(SpdyProxyClientSocketTest, ConnectSendsCorrectRequest) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 398 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 399 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 400 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 401 | }; |
| 402 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 403 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 404 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 405 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 406 | }; |
| 407 | |
| 408 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 409 | |
| 410 | ASSERT_FALSE(sock_->IsConnected()); |
| 411 | |
| 412 | AssertConnectSucceeds(); |
| 413 | |
| 414 | AssertConnectionEstablished(); |
| 415 | } |
| 416 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 417 | TEST_P(SpdyProxyClientSocketTest, ConnectWithAuthRequested) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 418 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 419 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 420 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 421 | }; |
| 422 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 423 | scoped_ptr<SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 424 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 425 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 426 | }; |
| 427 | |
| 428 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 429 | |
[email protected] | b40d5cb | 2012-02-27 05:30:18 | [diff] [blame] | 430 | AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 431 | |
| 432 | const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
| 433 | ASSERT_TRUE(response != NULL); |
| 434 | ASSERT_EQ(407, response->headers->response_code()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 435 | } |
| 436 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 437 | TEST_P(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 438 | scoped_ptr<SpdyFrame> conn(ConstructConnectAuthRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 439 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 440 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 441 | }; |
| 442 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 443 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 444 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 445 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 446 | }; |
| 447 | |
| 448 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 449 | AddAuthToCache(); |
| 450 | |
| 451 | AssertConnectSucceeds(); |
| 452 | |
| 453 | AssertConnectionEstablished(); |
| 454 | } |
| 455 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 456 | TEST_P(SpdyProxyClientSocketTest, ConnectRedirects) { |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 457 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 458 | scoped_ptr<SpdyFrame> rst( |
| 459 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 460 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 461 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | scoped_ptr<SpdyFrame> resp(ConstructConnectRedirectReplyFrame()); |
| 465 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 466 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 470 | |
| 471 | AssertConnectFails(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
| 472 | |
| 473 | const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
| 474 | ASSERT_TRUE(response != NULL); |
| 475 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 476 | const HttpResponseHeaders* headers = response->headers.get(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 477 | ASSERT_EQ(302, headers->response_code()); |
| 478 | ASSERT_FALSE(headers->HasHeader("set-cookie")); |
| 479 | ASSERT_TRUE(headers->HasHeaderValue("content-length", "0")); |
| 480 | |
| 481 | std::string location; |
| 482 | ASSERT_TRUE(headers->IsRedirect(&location)); |
| 483 | ASSERT_EQ(location, kRedirectUrl); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 484 | |
| 485 | // Let the RST_STREAM write while |rst| is in-scope. |
| 486 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 487 | } |
| 488 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 489 | TEST_P(SpdyProxyClientSocketTest, ConnectFails) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 490 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 491 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 492 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 493 | }; |
| 494 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 495 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 496 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 497 | MockRead(ASYNC, 0, 1), // EOF |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 498 | }; |
| 499 | |
| 500 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 501 | |
| 502 | ASSERT_FALSE(sock_->IsConnected()); |
| 503 | |
| 504 | AssertConnectFails(ERR_CONNECTION_CLOSED); |
| 505 | |
| 506 | ASSERT_FALSE(sock_->IsConnected()); |
| 507 | } |
| 508 | |
| 509 | // ----------- WasEverUsed |
| 510 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 511 | TEST_P(SpdyProxyClientSocketTest, WasEverUsedReturnsCorrectValues) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 512 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 513 | scoped_ptr<SpdyFrame> rst( |
| 514 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 515 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 516 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 517 | }; |
| 518 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 519 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 520 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 521 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 522 | }; |
| 523 | |
| 524 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 525 | |
| 526 | EXPECT_FALSE(sock_->WasEverUsed()); |
| 527 | AssertConnectSucceeds(); |
| 528 | EXPECT_TRUE(sock_->WasEverUsed()); |
| 529 | sock_->Disconnect(); |
| 530 | EXPECT_TRUE(sock_->WasEverUsed()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 531 | |
| 532 | // Let the RST_STREAM write while |rst| is in-scope. |
| 533 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | // ----------- GetPeerAddress |
| 537 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 538 | TEST_P(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 539 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 540 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 541 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 542 | }; |
| 543 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 544 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 545 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 546 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 547 | MockRead(ASYNC, 0, 3), // EOF |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 548 | }; |
| 549 | |
| 550 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 551 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 552 | IPEndPoint addr; |
[email protected] | 88e03fa | 2010-10-05 03:09:04 | [diff] [blame] | 553 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
| 554 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 555 | AssertConnectSucceeds(); |
| 556 | EXPECT_TRUE(sock_->IsConnected()); |
| 557 | EXPECT_EQ(OK, sock_->GetPeerAddress(&addr)); |
[email protected] | 88e03fa | 2010-10-05 03:09:04 | [diff] [blame] | 558 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 559 | ResumeAndRun(); |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 560 | |
| 561 | EXPECT_FALSE(sock_->IsConnected()); |
| 562 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
| 563 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 564 | sock_->Disconnect(); |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 565 | |
[email protected] | 88e03fa | 2010-10-05 03:09:04 | [diff] [blame] | 566 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | // ----------- Write |
| 570 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 571 | TEST_P(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 572 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 573 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 574 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 575 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 576 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
| 577 | CreateMockWrite(*msg1, 3, SYNCHRONOUS), |
| 578 | CreateMockWrite(*msg2, 4, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 579 | }; |
| 580 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 581 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 582 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 583 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 587 | |
| 588 | AssertConnectSucceeds(); |
| 589 | |
| 590 | AssertAsyncWriteSucceeds(kMsg1, kLen1); |
| 591 | AssertAsyncWriteSucceeds(kMsg2, kLen2); |
| 592 | } |
| 593 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 594 | TEST_P(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 595 | std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 596 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 597 | scoped_ptr<SpdyFrame> chunk(ConstructBodyFrame(chunk_data.data(), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 598 | chunk_data.length())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 599 | MockWrite writes[] = {CreateMockWrite(*conn, 0, SYNCHRONOUS), |
| 600 | CreateMockWrite(*chunk, 3, SYNCHRONOUS), |
| 601 | CreateMockWrite(*chunk, 4, SYNCHRONOUS), |
| 602 | CreateMockWrite(*chunk, 5, SYNCHRONOUS)}; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 603 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 604 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 605 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 606 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 610 | |
| 611 | AssertConnectSucceeds(); |
| 612 | |
| 613 | std::string big_data(kMaxSpdyFrameChunkSize * 3, 'x'); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 614 | scoped_refptr<IOBufferWithSize> buf(CreateBuffer(big_data.data(), |
| 615 | big_data.length())); |
| 616 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 617 | EXPECT_EQ(ERR_IO_PENDING, |
| 618 | sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 619 | EXPECT_EQ(buf->size(), write_callback_.WaitForResult()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // ----------- Read |
| 623 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 624 | TEST_P(SpdyProxyClientSocketTest, ReadReadsDataInDataFrame) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 625 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 626 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 627 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 628 | }; |
| 629 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 630 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 631 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 632 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 633 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 634 | CreateMockRead(*msg1, 3, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 4), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 635 | }; |
| 636 | |
| 637 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 638 | |
| 639 | AssertConnectSucceeds(); |
| 640 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 641 | // SpdySession consumes the next read and sends it to sock_ to be buffered. |
| 642 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 643 | AssertSyncReadEquals(kMsg1, kLen1); |
| 644 | } |
| 645 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 646 | TEST_P(SpdyProxyClientSocketTest, ReadDataFromBufferedFrames) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 647 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 648 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 649 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 650 | }; |
| 651 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 652 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 653 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 654 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 655 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 656 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 657 | CreateMockRead(*msg1, 3, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 658 | CreateMockRead(*msg2, 5, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 662 | |
| 663 | AssertConnectSucceeds(); |
| 664 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 665 | // SpdySession consumes the next read and sends it to sock_ to be buffered. |
| 666 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 667 | AssertSyncReadEquals(kMsg1, kLen1); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 668 | // SpdySession consumes the next read and sends it to sock_ to be buffered. |
| 669 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 670 | AssertSyncReadEquals(kMsg2, kLen2); |
| 671 | } |
| 672 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 673 | TEST_P(SpdyProxyClientSocketTest, ReadDataMultipleBufferedFrames) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 674 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 675 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 676 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 677 | }; |
| 678 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 679 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 680 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 681 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 682 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 683 | CreateMockRead(*resp, 1, ASYNC), |
| 684 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 685 | CreateMockRead(*msg1, 3, ASYNC), |
| 686 | CreateMockRead(*msg2, 4, ASYNC), |
| 687 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 691 | |
| 692 | AssertConnectSucceeds(); |
| 693 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 694 | // SpdySession consumes the next two reads and sends then to sock_ to be |
| 695 | // buffered. |
| 696 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 697 | AssertSyncReadEquals(kMsg1, kLen1); |
| 698 | AssertSyncReadEquals(kMsg2, kLen2); |
| 699 | } |
| 700 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 701 | TEST_P(SpdyProxyClientSocketTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 702 | LargeReadWillMergeDataFromDifferentFrames) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 703 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 704 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 705 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 706 | }; |
| 707 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 708 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 709 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 710 | scoped_ptr<SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 711 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 712 | CreateMockRead(*resp, 1, ASYNC), |
| 713 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 714 | CreateMockRead(*msg3, 3, ASYNC), |
| 715 | CreateMockRead(*msg3, 4, ASYNC), |
| 716 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 720 | |
| 721 | AssertConnectSucceeds(); |
| 722 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 723 | // SpdySession consumes the next two reads and sends then to sock_ to be |
| 724 | // buffered. |
| 725 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 726 | // The payload from two data frames, each with kMsg3 will be combined |
| 727 | // together into a single read(). |
| 728 | AssertSyncReadEquals(kMsg33, kLen33); |
| 729 | } |
| 730 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 731 | TEST_P(SpdyProxyClientSocketTest, MultipleShortReadsThenMoreRead) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 732 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 733 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 734 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 735 | }; |
| 736 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 737 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 738 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 739 | scoped_ptr<SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
| 740 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 741 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 742 | CreateMockRead(*resp, 1, ASYNC), |
| 743 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 744 | CreateMockRead(*msg1, 3, ASYNC), |
| 745 | CreateMockRead(*msg3, 4, ASYNC), |
| 746 | CreateMockRead(*msg3, 5, ASYNC), |
| 747 | CreateMockRead(*msg2, 6, ASYNC), |
| 748 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 749 | }; |
| 750 | |
| 751 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 752 | |
| 753 | AssertConnectSucceeds(); |
| 754 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 755 | // SpdySession consumes the next four reads and sends then to sock_ to be |
| 756 | // buffered. |
| 757 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 758 | AssertSyncReadEquals(kMsg1, kLen1); |
| 759 | // The payload from two data frames, each with kMsg3 will be combined |
| 760 | // together into a single read(). |
| 761 | AssertSyncReadEquals(kMsg33, kLen33); |
| 762 | AssertSyncReadEquals(kMsg2, kLen2); |
| 763 | } |
| 764 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 765 | TEST_P(SpdyProxyClientSocketTest, ReadWillSplitDataFromLargeFrame) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 766 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 767 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 768 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 769 | }; |
| 770 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 771 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 772 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 773 | scoped_ptr<SpdyFrame> msg33(ConstructBodyFrame(kMsg33, kLen33)); |
| 774 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 775 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 776 | CreateMockRead(*resp, 1, ASYNC), |
| 777 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 778 | CreateMockRead(*msg1, 3, ASYNC), |
| 779 | CreateMockRead(*msg33, 4, ASYNC), |
| 780 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 781 | }; |
| 782 | |
| 783 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 784 | |
| 785 | AssertConnectSucceeds(); |
| 786 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 787 | // SpdySession consumes the next two reads and sends then to sock_ to be |
| 788 | // buffered. |
| 789 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 790 | AssertSyncReadEquals(kMsg1, kLen1); |
| 791 | // The payload from the single large data frame will be read across |
| 792 | // two different reads. |
| 793 | AssertSyncReadEquals(kMsg3, kLen3); |
| 794 | AssertSyncReadEquals(kMsg3, kLen3); |
| 795 | } |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 796 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 797 | TEST_P(SpdyProxyClientSocketTest, MultipleReadsFromSameLargeFrame) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 798 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 799 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 800 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 801 | }; |
| 802 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 803 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 804 | scoped_ptr<SpdyFrame> msg333(ConstructBodyFrame(kMsg333, kLen333)); |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 805 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 806 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 807 | CreateMockRead(*msg333, 3, ASYNC), |
| 808 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 4), |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 809 | }; |
| 810 | |
| 811 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 812 | |
| 813 | AssertConnectSucceeds(); |
| 814 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 815 | // SpdySession consumes the next read and sends it to sock_ to be buffered. |
| 816 | ResumeAndRun(); |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 817 | // The payload from the single large data frame will be read across |
| 818 | // two different reads. |
| 819 | AssertSyncReadEquals(kMsg33, kLen33); |
| 820 | |
| 821 | // Now attempt to do a read of more data than remains buffered |
| 822 | scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 823 | ASSERT_EQ(kLen3, sock_->Read(buf.get(), kLen33, read_callback_.callback())); |
[email protected] | 87d3c4a | 2010-10-07 03:00:42 | [diff] [blame] | 824 | ASSERT_EQ(std::string(kMsg3, kLen3), std::string(buf->data(), kLen3)); |
| 825 | ASSERT_TRUE(sock_->IsConnected()); |
| 826 | } |
| 827 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 828 | TEST_P(SpdyProxyClientSocketTest, ReadAuthResponseBody) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 829 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 830 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 831 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 832 | }; |
| 833 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 834 | scoped_ptr<SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
| 835 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 836 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 837 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 838 | CreateMockRead(*resp, 1, ASYNC), |
| 839 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 840 | CreateMockRead(*msg1, 3, ASYNC), |
| 841 | CreateMockRead(*msg2, 4, ASYNC), |
| 842 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 843 | }; |
| 844 | |
| 845 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 846 | |
[email protected] | b40d5cb | 2012-02-27 05:30:18 | [diff] [blame] | 847 | AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 848 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 849 | // SpdySession consumes the next two reads and sends then to sock_ to be |
| 850 | // buffered. |
| 851 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 852 | AssertSyncReadEquals(kMsg1, kLen1); |
| 853 | AssertSyncReadEquals(kMsg2, kLen2); |
| 854 | } |
| 855 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 856 | TEST_P(SpdyProxyClientSocketTest, ReadErrorResponseBody) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 857 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 858 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 859 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 860 | }; |
| 861 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 862 | scoped_ptr<SpdyFrame> resp(ConstructConnectErrorReplyFrame()); |
| 863 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 864 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 865 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 866 | CreateMockRead(*resp, 1, ASYNC), |
| 867 | CreateMockRead(*msg1, 2, ASYNC), |
| 868 | CreateMockRead(*msg2, 3, ASYNC), |
| 869 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 870 | }; |
| 871 | |
| 872 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 873 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 874 | AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | // ----------- Reads and Writes |
| 878 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 879 | TEST_P(SpdyProxyClientSocketTest, AsyncReadAroundWrite) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 880 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 881 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 882 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 883 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
| 884 | CreateMockWrite(*msg2, 4, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 885 | }; |
| 886 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 887 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 888 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 889 | scoped_ptr<SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 890 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 891 | CreateMockRead(*resp, 1, ASYNC), |
| 892 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 893 | CreateMockRead(*msg1, 3, ASYNC), // sync read |
| 894 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
| 895 | CreateMockRead(*msg3, 6, ASYNC), // async read |
| 896 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 897 | }; |
| 898 | |
| 899 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 900 | |
| 901 | AssertConnectSucceeds(); |
| 902 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 903 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 904 | AssertSyncReadEquals(kMsg1, kLen1); |
| 905 | |
| 906 | AssertReadStarts(kMsg3, kLen3); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 907 | // Read should block until after the write succeeds. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 908 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 909 | AssertAsyncWriteSucceeds(kMsg2, kLen2); // Advances past paused read. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 910 | |
| 911 | ASSERT_FALSE(read_callback_.have_result()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 912 | ResumeAndRun(); |
| 913 | // Now the read will return. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 914 | AssertReadReturns(kMsg3, kLen3); |
| 915 | } |
| 916 | |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 917 | TEST_P(SpdyProxyClientSocketTest, AsyncWriteAroundReads) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 918 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 919 | scoped_ptr<SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 920 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 921 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
| 922 | MockWrite(ASYNC, ERR_IO_PENDING, 7), CreateMockWrite(*msg2, 8, ASYNC), |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 923 | }; |
| 924 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 925 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 926 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 927 | scoped_ptr<SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 928 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 929 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 930 | CreateMockRead(*msg1, 3, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 931 | CreateMockRead(*msg3, 5, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 932 | }; |
| 933 | |
| 934 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 935 | |
| 936 | AssertConnectSucceeds(); |
| 937 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 938 | ResumeAndRun(); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 939 | AssertSyncReadEquals(kMsg1, kLen1); |
| 940 | // Write should block until the read completes |
| 941 | AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING); |
| 942 | |
| 943 | AssertAsyncReadEquals(kMsg3, kLen3); |
| 944 | |
| 945 | ASSERT_FALSE(write_callback_.have_result()); |
| 946 | |
| 947 | // Now the write will complete |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 948 | ResumeAndRun(); |
[email protected] | 5e660958 | 2010-10-05 18:14:20 | [diff] [blame] | 949 | AssertWriteLength(kLen2); |
| 950 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 951 | |
| 952 | // ----------- Reading/Writing on Closed socket |
| 953 | |
| 954 | // Reading from an already closed socket should return 0 |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 955 | TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsZero) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 956 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 957 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 958 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 959 | }; |
| 960 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 961 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 962 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 963 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 964 | MockRead(ASYNC, 0, 3), // EOF |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 965 | }; |
| 966 | |
| 967 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 968 | |
| 969 | AssertConnectSucceeds(); |
| 970 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 971 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 972 | |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 973 | ASSERT_FALSE(sock_->IsConnected()); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 974 | ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
| 975 | ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
| 976 | ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
[email protected] | 43549a8f | 2011-05-16 23:37:15 | [diff] [blame] | 977 | ASSERT_FALSE(sock_->IsConnectedAndIdle()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 978 | } |
| 979 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 980 | // Read pending when socket is closed should return 0 |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 981 | TEST_P(SpdyProxyClientSocketTest, PendingReadOnCloseReturnsZero) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 982 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 983 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 984 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 985 | }; |
| 986 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 987 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 988 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 989 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 990 | MockRead(ASYNC, 0, 3), // EOF |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 994 | |
| 995 | AssertConnectSucceeds(); |
| 996 | |
| 997 | AssertReadStarts(kMsg1, kLen1); |
| 998 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 999 | ResumeAndRun(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1000 | |
| 1001 | ASSERT_EQ(0, read_callback_.WaitForResult()); |
| 1002 | } |
| 1003 | |
| 1004 | // Reading from a disconnected socket is an error |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1005 | TEST_P(SpdyProxyClientSocketTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1006 | ReadOnDisconnectSocketReturnsNotConnected) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1007 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1008 | scoped_ptr<SpdyFrame> rst( |
| 1009 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1010 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1011 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1012 | }; |
| 1013 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1014 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1015 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1016 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1017 | }; |
| 1018 | |
| 1019 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1020 | |
| 1021 | AssertConnectSucceeds(); |
| 1022 | |
| 1023 | sock_->Disconnect(); |
| 1024 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1025 | ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
| 1026 | sock_->Read(NULL, 1, CompletionCallback())); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1027 | |
| 1028 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1029 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | // Reading buffered data from an already closed socket should return |
| 1033 | // buffered data, then 0. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1034 | TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1035 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1036 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1037 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1038 | }; |
| 1039 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1040 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 1041 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1042 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1043 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1044 | CreateMockRead(*msg1, 3, ASYNC), MockRead(ASYNC, 0, 4), // EOF |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1045 | }; |
| 1046 | |
| 1047 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1048 | |
| 1049 | AssertConnectSucceeds(); |
| 1050 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1051 | ResumeAndRun(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1052 | |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 1053 | ASSERT_FALSE(sock_->IsConnected()); |
| 1054 | scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1055 | ASSERT_EQ(kLen1, sock_->Read(buf.get(), kLen1, CompletionCallback())); |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 1056 | ASSERT_EQ(std::string(kMsg1, kLen1), std::string(buf->data(), kLen1)); |
| 1057 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1058 | ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
| 1059 | ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 1060 | sock_->Disconnect(); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1061 | ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
| 1062 | sock_->Read(NULL, 1, CompletionCallback())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1063 | } |
| 1064 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1065 | // Calling Write() on a closed socket is an error |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1066 | TEST_P(SpdyProxyClientSocketTest, WriteOnClosedStream) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1067 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1068 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1069 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1070 | }; |
| 1071 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1072 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 1073 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1074 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1075 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1076 | MockRead(ASYNC, 0, 3), // EOF |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1077 | }; |
| 1078 | |
| 1079 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1080 | |
| 1081 | AssertConnectSucceeds(); |
| 1082 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1083 | // Read EOF which will close the stream. |
| 1084 | ResumeAndRun(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1085 | scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1086 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1087 | sock_->Write(buf.get(), buf->size(), CompletionCallback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1088 | } |
| 1089 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1090 | // Calling Write() on a disconnected socket is an error. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1091 | TEST_P(SpdyProxyClientSocketTest, WriteOnDisconnectedSocket) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1092 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1093 | scoped_ptr<SpdyFrame> rst( |
| 1094 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1095 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1096 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1097 | }; |
| 1098 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1099 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 1100 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1101 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1102 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1103 | }; |
| 1104 | |
| 1105 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1106 | |
| 1107 | AssertConnectSucceeds(); |
| 1108 | |
| 1109 | sock_->Disconnect(); |
| 1110 | |
| 1111 | scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1112 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1113 | sock_->Write(buf.get(), buf->size(), CompletionCallback())); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1114 | |
| 1115 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1116 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1117 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1118 | |
| 1119 | // If the socket is closed with a pending Write(), the callback |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1120 | // should be called with ERR_CONNECTION_CLOSED. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1121 | TEST_P(SpdyProxyClientSocketTest, WritePendingOnClose) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1122 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1123 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1124 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
| 1125 | MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1126 | }; |
| 1127 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1128 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1129 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1130 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1134 | |
| 1135 | AssertConnectSucceeds(); |
| 1136 | |
| 1137 | EXPECT_TRUE(sock_->IsConnected()); |
| 1138 | |
| 1139 | scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1140 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1141 | sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1142 | // Make sure the write actually starts. |
| 1143 | base::RunLoop().RunUntilIdle(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1144 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 1145 | CloseSpdySession(ERR_ABORTED, std::string()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1146 | |
| 1147 | EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); |
| 1148 | } |
| 1149 | |
| 1150 | // If the socket is Disconnected with a pending Write(), the callback |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1151 | // should not be called. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1152 | TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1153 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1154 | scoped_ptr<SpdyFrame> rst( |
| 1155 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1156 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1157 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1158 | }; |
| 1159 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1160 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1161 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1162 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1163 | }; |
| 1164 | |
| 1165 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1166 | |
| 1167 | AssertConnectSucceeds(); |
| 1168 | |
| 1169 | EXPECT_TRUE(sock_->IsConnected()); |
| 1170 | |
| 1171 | scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1172 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1173 | sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1174 | |
| 1175 | sock_->Disconnect(); |
| 1176 | |
| 1177 | EXPECT_FALSE(sock_->IsConnected()); |
| 1178 | EXPECT_FALSE(write_callback_.have_result()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1179 | |
| 1180 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1181 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1182 | } |
| 1183 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 1184 | // If the socket is Disconnected with a pending Read(), the callback |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1185 | // should not be called. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1186 | TEST_P(SpdyProxyClientSocketTest, DisconnectWithReadPending) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1187 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1188 | scoped_ptr<SpdyFrame> rst( |
| 1189 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1190 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1191 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1192 | }; |
| 1193 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1194 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1195 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1196 | CreateMockRead(*resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1197 | }; |
| 1198 | |
| 1199 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1200 | |
| 1201 | AssertConnectSucceeds(); |
| 1202 | |
| 1203 | EXPECT_TRUE(sock_->IsConnected()); |
| 1204 | |
| 1205 | scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1206 | ASSERT_EQ(ERR_IO_PENDING, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1207 | sock_->Read(buf.get(), kLen1, read_callback_.callback())); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1208 | |
| 1209 | sock_->Disconnect(); |
| 1210 | |
| 1211 | EXPECT_FALSE(sock_->IsConnected()); |
| 1212 | EXPECT_FALSE(read_callback_.have_result()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1213 | |
| 1214 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1215 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1216 | } |
| 1217 | |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1218 | // If the socket is Reset when both a read and write are pending, |
| 1219 | // both should be called back. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1220 | TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1221 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1222 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1223 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1224 | }; |
| 1225 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1226 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1227 | scoped_ptr<SpdyFrame> rst( |
| 1228 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1229 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1230 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1231 | CreateMockRead(*rst, 3, ASYNC), MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1232 | }; |
| 1233 | |
| 1234 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1235 | |
| 1236 | AssertConnectSucceeds(); |
| 1237 | |
| 1238 | EXPECT_TRUE(sock_->IsConnected()); |
| 1239 | |
| 1240 | scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1241 | ASSERT_EQ(ERR_IO_PENDING, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1242 | sock_->Read(read_buf.get(), kLen1, read_callback_.callback())); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1243 | |
| 1244 | scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1245 | EXPECT_EQ( |
| 1246 | ERR_IO_PENDING, |
| 1247 | sock_->Write( |
| 1248 | write_buf.get(), write_buf->size(), write_callback_.callback())); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1249 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1250 | ResumeAndRun(); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1251 | |
| 1252 | EXPECT_TRUE(sock_.get()); |
| 1253 | EXPECT_TRUE(read_callback_.have_result()); |
| 1254 | EXPECT_TRUE(write_callback_.have_result()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1255 | |
| 1256 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1257 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1258 | } |
| 1259 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1260 | // Makes sure the proxy client socket's source gets the expected NetLog events |
| 1261 | // and only the expected NetLog events (No SpdySession events). |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1262 | TEST_P(SpdyProxyClientSocketTest, NetLog) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1263 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1264 | scoped_ptr<SpdyFrame> rst( |
| 1265 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1266 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1267 | CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1268 | }; |
| 1269 | |
| 1270 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 1271 | scoped_ptr<SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
| 1272 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1273 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1274 | CreateMockRead(*msg1, 3, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 4), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1275 | }; |
| 1276 | |
| 1277 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1278 | |
| 1279 | AssertConnectSucceeds(); |
| 1280 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1281 | // SpdySession consumes the next read and sends it to sock_ to be buffered. |
| 1282 | ResumeAndRun(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1283 | AssertSyncReadEquals(kMsg1, kLen1); |
| 1284 | |
| 1285 | NetLog::Source sock_source = sock_->NetLog().source(); |
| 1286 | sock_.reset(); |
| 1287 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 1288 | TestNetLogEntry::List entry_list; |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1289 | net_log_.GetEntriesForSource(sock_source, &entry_list); |
| 1290 | |
| 1291 | ASSERT_EQ(entry_list.size(), 10u); |
| 1292 | EXPECT_TRUE(LogContainsBeginEvent(entry_list, 0, NetLog::TYPE_SOCKET_ALIVE)); |
| 1293 | EXPECT_TRUE(LogContainsEvent(entry_list, 1, |
bnc | be32a03 | 2015-02-25 17:22:55 | [diff] [blame] | 1294 | NetLog::TYPE_HTTP2_PROXY_CLIENT_SESSION, |
| 1295 | NetLog::PHASE_NONE)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1296 | EXPECT_TRUE(LogContainsBeginEvent(entry_list, 2, |
| 1297 | NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_SEND_REQUEST)); |
| 1298 | EXPECT_TRUE(LogContainsEvent(entry_list, 3, |
| 1299 | NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 1300 | NetLog::PHASE_NONE)); |
| 1301 | EXPECT_TRUE(LogContainsEndEvent(entry_list, 4, |
| 1302 | NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_SEND_REQUEST)); |
| 1303 | EXPECT_TRUE(LogContainsBeginEvent(entry_list, 5, |
| 1304 | NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS)); |
| 1305 | EXPECT_TRUE(LogContainsEvent(entry_list, 6, |
| 1306 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 1307 | NetLog::PHASE_NONE)); |
| 1308 | EXPECT_TRUE(LogContainsEndEvent(entry_list, 7, |
| 1309 | NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS)); |
| 1310 | EXPECT_TRUE(LogContainsEvent(entry_list, 8, |
| 1311 | NetLog::TYPE_SOCKET_BYTES_RECEIVED, |
| 1312 | NetLog::PHASE_NONE)); |
| 1313 | EXPECT_TRUE(LogContainsEndEvent(entry_list, 9, NetLog::TYPE_SOCKET_ALIVE)); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1314 | |
| 1315 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1316 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 1317 | } |
| 1318 | |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1319 | // CompletionCallback that causes the SpdyProxyClientSocket to be |
| 1320 | // deleted when Run is invoked. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1321 | class DeleteSockCallback : public TestCompletionCallbackBase { |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1322 | public: |
| 1323 | explicit DeleteSockCallback(scoped_ptr<SpdyProxyClientSocket>* sock) |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1324 | : sock_(sock), |
| 1325 | callback_(base::Bind(&DeleteSockCallback::OnComplete, |
| 1326 | base::Unretained(this))) { |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1327 | } |
| 1328 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 1329 | ~DeleteSockCallback() override {} |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1331 | const CompletionCallback& callback() const { return callback_; } |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1332 | |
| 1333 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1334 | void OnComplete(int result) { |
| 1335 | sock_->reset(NULL); |
| 1336 | SetResult(result); |
| 1337 | } |
| 1338 | |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1339 | scoped_ptr<SpdyProxyClientSocket>* sock_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1340 | CompletionCallback callback_; |
| 1341 | |
| 1342 | DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1343 | }; |
| 1344 | |
| 1345 | // If the socket is Reset when both a read and write are pending, and the |
| 1346 | // read callback causes the socket to be deleted, the write callback should |
| 1347 | // not be called. |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 1348 | TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1349 | scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1350 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1351 | CreateMockWrite(*conn, 0, SYNCHRONOUS), |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1352 | }; |
| 1353 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1354 | scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1355 | scoped_ptr<SpdyFrame> rst( |
| 1356 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1357 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1358 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1359 | CreateMockRead(*rst, 3, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 4), |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1360 | }; |
| 1361 | |
| 1362 | Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1363 | |
| 1364 | AssertConnectSucceeds(); |
| 1365 | |
| 1366 | EXPECT_TRUE(sock_->IsConnected()); |
| 1367 | |
| 1368 | DeleteSockCallback read_callback(&sock_); |
| 1369 | |
| 1370 | scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 1371 | ASSERT_EQ(ERR_IO_PENDING, |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1372 | sock_->Read(read_buf.get(), kLen1, read_callback.callback())); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1373 | |
| 1374 | scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1375 | EXPECT_EQ( |
| 1376 | ERR_IO_PENDING, |
| 1377 | sock_->Write( |
| 1378 | write_buf.get(), write_buf->size(), write_callback_.callback())); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1379 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1380 | ResumeAndRun(); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1381 | |
| 1382 | EXPECT_FALSE(sock_.get()); |
| 1383 | EXPECT_TRUE(read_callback.have_result()); |
| 1384 | EXPECT_FALSE(write_callback_.have_result()); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 1385 | |
| 1386 | // Let the RST_STREAM write while |rst| is in-scope. |
| 1387 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 1390 | } // namespace net |