OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 "Basic realm=MyRealm1", | 101 "Basic realm=MyRealm1", |
102 AuthCredentials(kFoo, kBar), | 102 AuthCredentials(kFoo, kBar), |
103 "/"); | 103 "/"); |
104 } | 104 } |
105 | 105 |
106 void Run(int steps) { | 106 void Run(int steps) { |
107 data_->StopAfter(steps); | 107 data_->StopAfter(steps); |
108 data_->Run(); | 108 data_->Run(); |
109 } | 109 } |
110 | 110 |
| 111 void CloseSpdySession(net::Error error, const std::string& description) { |
| 112 spdy_session_->CloseSessionOnError(error, description); |
| 113 } |
| 114 |
111 SpdyTestUtil spdy_util_; | 115 SpdyTestUtil spdy_util_; |
112 scoped_ptr<SpdyProxyClientSocket> sock_; | 116 scoped_ptr<SpdyProxyClientSocket> sock_; |
113 TestCompletionCallback read_callback_; | 117 TestCompletionCallback read_callback_; |
114 TestCompletionCallback write_callback_; | 118 TestCompletionCallback write_callback_; |
115 scoped_ptr<DeterministicSocketData> data_; | 119 scoped_ptr<DeterministicSocketData> data_; |
116 CapturingBoundNetLog net_log_; | 120 CapturingBoundNetLog net_log_; |
117 | 121 |
118 private: | 122 private: |
119 scoped_refptr<HttpNetworkSession> session_; | 123 scoped_refptr<HttpNetworkSession> session_; |
120 scoped_refptr<IOBuffer> read_buf_; | 124 scoped_refptr<IOBuffer> read_buf_; |
121 SpdySessionDependencies session_deps_; | 125 SpdySessionDependencies session_deps_; |
122 MockConnect connect_data_; | 126 MockConnect connect_data_; |
123 scoped_refptr<SpdySession> spdy_session_; | 127 base::WeakPtr<SpdySession> spdy_session_; |
124 BufferedSpdyFramer framer_; | 128 BufferedSpdyFramer framer_; |
125 | 129 |
126 std::string user_agent_; | 130 std::string user_agent_; |
127 GURL url_; | 131 GURL url_; |
128 HostPortPair proxy_host_port_; | 132 HostPortPair proxy_host_port_; |
129 HostPortPair endpoint_host_port_pair_; | 133 HostPortPair endpoint_host_port_pair_; |
130 ProxyServer proxy_; | 134 ProxyServer proxy_; |
131 SpdySessionKey endpoint_spdy_session_key_; | 135 SpdySessionKey endpoint_spdy_session_key_; |
132 | 136 |
133 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); | 137 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); |
134 }; | 138 }; |
135 | 139 |
136 INSTANTIATE_TEST_CASE_P( | 140 INSTANTIATE_TEST_CASE_P( |
137 NextProto, | 141 NextProto, |
138 SpdyProxyClientSocketTest, | 142 SpdyProxyClientSocketTest, |
139 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); | 143 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); |
140 | 144 |
141 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() | 145 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() |
142 : spdy_util_(GetParam()), | 146 : spdy_util_(GetParam()), |
143 session_(NULL), | 147 session_(NULL), |
144 read_buf_(NULL), | 148 read_buf_(NULL), |
145 session_deps_(GetParam()), | 149 session_deps_(GetParam()), |
146 connect_data_(SYNCHRONOUS, OK), | 150 connect_data_(SYNCHRONOUS, OK), |
147 spdy_session_(NULL), | |
148 framer_(spdy_util_.spdy_version(), false), | 151 framer_(spdy_util_.spdy_version(), false), |
149 user_agent_(kUserAgent), | 152 user_agent_(kUserAgent), |
150 url_(kRequestUrl), | 153 url_(kRequestUrl), |
151 proxy_host_port_(kProxyHost, kProxyPort), | 154 proxy_host_port_(kProxyHost, kProxyPort), |
152 endpoint_host_port_pair_(kOriginHost, kOriginPort), | 155 endpoint_host_port_pair_(kOriginHost, kOriginPort), |
153 proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), | 156 proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), |
154 endpoint_spdy_session_key_(endpoint_host_port_pair_, | 157 endpoint_spdy_session_key_(endpoint_host_port_pair_, |
155 proxy_, | 158 proxy_, |
156 kPrivacyModeDisabled) { | 159 kPrivacyModeDisabled) { |
157 session_deps_.net_log = net_log_.bound().net_log(); | 160 session_deps_.net_log = net_log_.bound().net_log(); |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1191 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1189 | 1192 |
1190 AssertConnectSucceeds(); | 1193 AssertConnectSucceeds(); |
1191 | 1194 |
1192 EXPECT_TRUE(sock_->IsConnected()); | 1195 EXPECT_TRUE(sock_->IsConnected()); |
1193 | 1196 |
1194 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1197 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1195 EXPECT_EQ(ERR_IO_PENDING, | 1198 EXPECT_EQ(ERR_IO_PENDING, |
1196 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); | 1199 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
1197 | 1200 |
1198 Run(1); | 1201 CloseSpdySession(ERR_ABORTED, std::string()); |
1199 | 1202 |
1200 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); | 1203 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); |
1201 } | 1204 } |
1202 | 1205 |
1203 // If the socket is Disconnected with a pending Write(), the callback | 1206 // If the socket is Disconnected with a pending Write(), the callback |
1204 // should not be called. | 1207 // should not be called. |
1205 TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) { | 1208 TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) { |
1206 scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); | 1209 scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
1207 MockWrite writes[] = { | 1210 MockWrite writes[] = { |
1208 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1211 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 EXPECT_FALSE(sock_->IsConnected()); | 1263 EXPECT_FALSE(sock_->IsConnected()); |
1261 EXPECT_FALSE(read_callback_.have_result()); | 1264 EXPECT_FALSE(read_callback_.have_result()); |
1262 } | 1265 } |
1263 | 1266 |
1264 // If the socket is Reset when both a read and write are pending, | 1267 // If the socket is Reset when both a read and write are pending, |
1265 // both should be called back. | 1268 // both should be called back. |
1266 TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { | 1269 TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { |
1267 scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); | 1270 scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
1268 MockWrite writes[] = { | 1271 MockWrite writes[] = { |
1269 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1272 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1270 MockWrite(ASYNC, ERR_ABORTED, 2), | 1273 MockWrite(ASYNC, ERR_ABORTED, 3), |
1271 }; | 1274 }; |
1272 | 1275 |
1273 scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); | 1276 scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
1274 scoped_ptr<SpdyFrame> rst( | 1277 scoped_ptr<SpdyFrame> rst( |
1275 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 1278 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
1276 MockRead reads[] = { | 1279 MockRead reads[] = { |
1277 CreateMockRead(*resp, 1, ASYNC), | 1280 CreateMockRead(*resp, 1, ASYNC), |
1278 CreateMockRead(*rst, 3, ASYNC), | 1281 CreateMockRead(*rst, 2, ASYNC), |
| 1282 MockRead(ASYNC, 0, 4) // EOF |
1279 }; | 1283 }; |
1280 | 1284 |
1281 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1285 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1282 | 1286 |
1283 AssertConnectSucceeds(); | 1287 AssertConnectSucceeds(); |
1284 | 1288 |
1285 EXPECT_TRUE(sock_->IsConnected()); | 1289 EXPECT_TRUE(sock_->IsConnected()); |
1286 | 1290 |
1287 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); | 1291 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); |
1288 ASSERT_EQ(ERR_IO_PENDING, | 1292 ASSERT_EQ(ERR_IO_PENDING, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); | 1387 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); |
1384 }; | 1388 }; |
1385 | 1389 |
1386 // If the socket is Reset when both a read and write are pending, and the | 1390 // If the socket is Reset when both a read and write are pending, and the |
1387 // read callback causes the socket to be deleted, the write callback should | 1391 // read callback causes the socket to be deleted, the write callback should |
1388 // not be called. | 1392 // not be called. |
1389 TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { | 1393 TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { |
1390 scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); | 1394 scoped_ptr<SpdyFrame> conn(ConstructConnectRequestFrame()); |
1391 MockWrite writes[] = { | 1395 MockWrite writes[] = { |
1392 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1396 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1393 MockWrite(ASYNC, ERR_ABORTED, 2), | 1397 MockWrite(ASYNC, ERR_ABORTED, 3), |
1394 }; | 1398 }; |
1395 | 1399 |
1396 scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); | 1400 scoped_ptr<SpdyFrame> resp(ConstructConnectReplyFrame()); |
1397 scoped_ptr<SpdyFrame> rst( | 1401 scoped_ptr<SpdyFrame> rst( |
1398 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 1402 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
1399 MockRead reads[] = { | 1403 MockRead reads[] = { |
1400 CreateMockRead(*resp, 1, ASYNC), | 1404 CreateMockRead(*resp, 1, ASYNC), |
1401 CreateMockRead(*rst, 3, ASYNC), | 1405 CreateMockRead(*rst, 2, ASYNC), |
| 1406 MockRead(ASYNC, 0, 4), // EOF |
1402 }; | 1407 }; |
1403 | 1408 |
1404 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1409 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1405 | 1410 |
1406 AssertConnectSucceeds(); | 1411 AssertConnectSucceeds(); |
1407 | 1412 |
1408 EXPECT_TRUE(sock_->IsConnected()); | 1413 EXPECT_TRUE(sock_->IsConnected()); |
1409 | 1414 |
1410 DeleteSockCallback read_callback(&sock_); | 1415 DeleteSockCallback read_callback(&sock_); |
1411 | 1416 |
1412 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); | 1417 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); |
1413 ASSERT_EQ(ERR_IO_PENDING, | 1418 ASSERT_EQ(ERR_IO_PENDING, |
1414 sock_->Read(read_buf.get(), kLen1, read_callback.callback())); | 1419 sock_->Read(read_buf.get(), kLen1, read_callback.callback())); |
1415 | 1420 |
1416 scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); | 1421 scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); |
1417 EXPECT_EQ( | 1422 EXPECT_EQ( |
1418 ERR_IO_PENDING, | 1423 ERR_IO_PENDING, |
1419 sock_->Write( | 1424 sock_->Write( |
1420 write_buf.get(), write_buf->size(), write_callback_.callback())); | 1425 write_buf.get(), write_buf->size(), write_callback_.callback())); |
1421 | 1426 |
1422 Run(2); | 1427 Run(1); |
1423 | 1428 |
1424 EXPECT_FALSE(sock_.get()); | 1429 EXPECT_FALSE(sock_.get()); |
1425 EXPECT_TRUE(read_callback.have_result()); | 1430 EXPECT_TRUE(read_callback.have_result()); |
1426 EXPECT_FALSE(write_callback_.have_result()); | 1431 EXPECT_FALSE(write_callback_.have_result()); |
1427 } | 1432 } |
1428 | 1433 |
1429 } // namespace net | 1434 } // namespace net |
OLD | NEW |