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/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 SpdyProxyClientSocketTest::~SpdyProxyClientSocketTest() { | 185 SpdyProxyClientSocketTest::~SpdyProxyClientSocketTest() { |
186 EXPECT_TRUE(data_->AllWriteDataConsumed()); | 186 EXPECT_TRUE(data_->AllWriteDataConsumed()); |
187 EXPECT_TRUE(data_->AllReadDataConsumed()); | 187 EXPECT_TRUE(data_->AllReadDataConsumed()); |
188 } | 188 } |
189 | 189 |
190 void SpdyProxyClientSocketTest::TearDown() { | 190 void SpdyProxyClientSocketTest::TearDown() { |
191 if (session_.get() != NULL) | 191 if (session_.get() != NULL) |
192 session_->spdy_session_pool()->CloseAllSessions(); | 192 session_->spdy_session_pool()->CloseAllSessions(); |
193 | 193 |
194 // Empty the current queue. | 194 // Empty the current queue. |
195 base::MessageLoop::current()->RunUntilIdle(); | 195 base::RunLoop().RunUntilIdle(); |
196 PlatformTest::TearDown(); | 196 PlatformTest::TearDown(); |
197 } | 197 } |
198 | 198 |
199 NextProto SpdyProxyClientSocketTest::GetProtocol() const { | 199 NextProto SpdyProxyClientSocketTest::GetProtocol() const { |
200 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; | 200 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
201 } | 201 } |
202 | 202 |
203 bool SpdyProxyClientSocketTest::GetDependenciesFromPriority() const { | 203 bool SpdyProxyClientSocketTest::GetDependenciesFromPriority() const { |
204 return GetParam() == kTestCaseHTTP2PriorityDependencies; | 204 return GetParam() == kTestCaseHTTP2PriorityDependencies; |
205 } | 205 } |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 const HttpResponseHeaders* headers = response->headers.get(); | 478 const HttpResponseHeaders* headers = response->headers.get(); |
479 ASSERT_EQ(302, headers->response_code()); | 479 ASSERT_EQ(302, headers->response_code()); |
480 ASSERT_FALSE(headers->HasHeader("set-cookie")); | 480 ASSERT_FALSE(headers->HasHeader("set-cookie")); |
481 ASSERT_TRUE(headers->HasHeaderValue("content-length", "0")); | 481 ASSERT_TRUE(headers->HasHeaderValue("content-length", "0")); |
482 | 482 |
483 std::string location; | 483 std::string location; |
484 ASSERT_TRUE(headers->IsRedirect(&location)); | 484 ASSERT_TRUE(headers->IsRedirect(&location)); |
485 ASSERT_EQ(location, kRedirectUrl); | 485 ASSERT_EQ(location, kRedirectUrl); |
486 | 486 |
487 // Let the RST_STREAM write while |rst| is in-scope. | 487 // Let the RST_STREAM write while |rst| is in-scope. |
488 base::MessageLoop::current()->RunUntilIdle(); | 488 base::RunLoop().RunUntilIdle(); |
489 } | 489 } |
490 | 490 |
491 TEST_P(SpdyProxyClientSocketTest, ConnectFails) { | 491 TEST_P(SpdyProxyClientSocketTest, ConnectFails) { |
492 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 492 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
493 MockWrite writes[] = { | 493 MockWrite writes[] = { |
494 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 494 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
495 }; | 495 }; |
496 | 496 |
497 std::unique_ptr<SpdySerializedFrame> resp(ConstructConnectReplyFrame()); | 497 std::unique_ptr<SpdySerializedFrame> resp(ConstructConnectReplyFrame()); |
498 MockRead reads[] = { | 498 MockRead reads[] = { |
(...skipping 26 matching lines...) Expand all Loading... |
525 | 525 |
526 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 526 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
527 | 527 |
528 EXPECT_FALSE(sock_->WasEverUsed()); | 528 EXPECT_FALSE(sock_->WasEverUsed()); |
529 AssertConnectSucceeds(); | 529 AssertConnectSucceeds(); |
530 EXPECT_TRUE(sock_->WasEverUsed()); | 530 EXPECT_TRUE(sock_->WasEverUsed()); |
531 sock_->Disconnect(); | 531 sock_->Disconnect(); |
532 EXPECT_TRUE(sock_->WasEverUsed()); | 532 EXPECT_TRUE(sock_->WasEverUsed()); |
533 | 533 |
534 // Let the RST_STREAM write while |rst| is in-scope. | 534 // Let the RST_STREAM write while |rst| is in-scope. |
535 base::MessageLoop::current()->RunUntilIdle(); | 535 base::RunLoop().RunUntilIdle(); |
536 } | 536 } |
537 | 537 |
538 // ----------- GetPeerAddress | 538 // ----------- GetPeerAddress |
539 | 539 |
540 TEST_P(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) { | 540 TEST_P(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) { |
541 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 541 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
542 MockWrite writes[] = { | 542 MockWrite writes[] = { |
543 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 543 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
544 }; | 544 }; |
545 | 545 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1023 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1024 | 1024 |
1025 AssertConnectSucceeds(); | 1025 AssertConnectSucceeds(); |
1026 | 1026 |
1027 sock_->Disconnect(); | 1027 sock_->Disconnect(); |
1028 | 1028 |
1029 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1029 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1030 sock_->Read(NULL, 1, CompletionCallback())); | 1030 sock_->Read(NULL, 1, CompletionCallback())); |
1031 | 1031 |
1032 // Let the RST_STREAM write while |rst| is in-scope. | 1032 // Let the RST_STREAM write while |rst| is in-scope. |
1033 base::MessageLoop::current()->RunUntilIdle(); | 1033 base::RunLoop().RunUntilIdle(); |
1034 } | 1034 } |
1035 | 1035 |
1036 // Reading buffered data from an already closed socket should return | 1036 // Reading buffered data from an already closed socket should return |
1037 // buffered data, then 0. | 1037 // buffered data, then 0. |
1038 TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) { | 1038 TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) { |
1039 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 1039 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
1040 MockWrite writes[] = { | 1040 MockWrite writes[] = { |
1041 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1041 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1042 }; | 1042 }; |
1043 | 1043 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 | 1110 |
1111 AssertConnectSucceeds(); | 1111 AssertConnectSucceeds(); |
1112 | 1112 |
1113 sock_->Disconnect(); | 1113 sock_->Disconnect(); |
1114 | 1114 |
1115 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1115 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1116 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1116 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1117 sock_->Write(buf.get(), buf->size(), CompletionCallback())); | 1117 sock_->Write(buf.get(), buf->size(), CompletionCallback())); |
1118 | 1118 |
1119 // Let the RST_STREAM write while |rst| is in-scope. | 1119 // Let the RST_STREAM write while |rst| is in-scope. |
1120 base::MessageLoop::current()->RunUntilIdle(); | 1120 base::RunLoop().RunUntilIdle(); |
1121 } | 1121 } |
1122 | 1122 |
1123 // If the socket is closed with a pending Write(), the callback | 1123 // If the socket is closed with a pending Write(), the callback |
1124 // should be called with ERR_CONNECTION_CLOSED. | 1124 // should be called with ERR_CONNECTION_CLOSED. |
1125 TEST_P(SpdyProxyClientSocketTest, WritePendingOnClose) { | 1125 TEST_P(SpdyProxyClientSocketTest, WritePendingOnClose) { |
1126 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 1126 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
1127 MockWrite writes[] = { | 1127 MockWrite writes[] = { |
1128 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1128 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1129 MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 3), | 1129 MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 3), |
1130 }; | 1130 }; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1175 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1176 EXPECT_EQ(ERR_IO_PENDING, | 1176 EXPECT_EQ(ERR_IO_PENDING, |
1177 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); | 1177 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
1178 | 1178 |
1179 sock_->Disconnect(); | 1179 sock_->Disconnect(); |
1180 | 1180 |
1181 EXPECT_FALSE(sock_->IsConnected()); | 1181 EXPECT_FALSE(sock_->IsConnected()); |
1182 EXPECT_FALSE(write_callback_.have_result()); | 1182 EXPECT_FALSE(write_callback_.have_result()); |
1183 | 1183 |
1184 // Let the RST_STREAM write while |rst| is in-scope. | 1184 // Let the RST_STREAM write while |rst| is in-scope. |
1185 base::MessageLoop::current()->RunUntilIdle(); | 1185 base::RunLoop().RunUntilIdle(); |
1186 } | 1186 } |
1187 | 1187 |
1188 // If the socket is Disconnected with a pending Read(), the callback | 1188 // If the socket is Disconnected with a pending Read(), the callback |
1189 // should not be called. | 1189 // should not be called. |
1190 TEST_P(SpdyProxyClientSocketTest, DisconnectWithReadPending) { | 1190 TEST_P(SpdyProxyClientSocketTest, DisconnectWithReadPending) { |
1191 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 1191 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
1192 std::unique_ptr<SpdySerializedFrame> rst( | 1192 std::unique_ptr<SpdySerializedFrame> rst( |
1193 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 1193 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
1194 MockWrite writes[] = { | 1194 MockWrite writes[] = { |
1195 CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), | 1195 CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
(...skipping 13 matching lines...) Expand all Loading... |
1209 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); | 1209 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); |
1210 ASSERT_EQ(ERR_IO_PENDING, | 1210 ASSERT_EQ(ERR_IO_PENDING, |
1211 sock_->Read(buf.get(), kLen1, read_callback_.callback())); | 1211 sock_->Read(buf.get(), kLen1, read_callback_.callback())); |
1212 | 1212 |
1213 sock_->Disconnect(); | 1213 sock_->Disconnect(); |
1214 | 1214 |
1215 EXPECT_FALSE(sock_->IsConnected()); | 1215 EXPECT_FALSE(sock_->IsConnected()); |
1216 EXPECT_FALSE(read_callback_.have_result()); | 1216 EXPECT_FALSE(read_callback_.have_result()); |
1217 | 1217 |
1218 // Let the RST_STREAM write while |rst| is in-scope. | 1218 // Let the RST_STREAM write while |rst| is in-scope. |
1219 base::MessageLoop::current()->RunUntilIdle(); | 1219 base::RunLoop().RunUntilIdle(); |
1220 } | 1220 } |
1221 | 1221 |
1222 // If the socket is Reset when both a read and write are pending, | 1222 // If the socket is Reset when both a read and write are pending, |
1223 // both should be called back. | 1223 // both should be called back. |
1224 TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { | 1224 TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { |
1225 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 1225 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
1226 MockWrite writes[] = { | 1226 MockWrite writes[] = { |
1227 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1227 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1228 }; | 1228 }; |
1229 | 1229 |
(...skipping 21 matching lines...) Expand all Loading... |
1251 sock_->Write( | 1251 sock_->Write( |
1252 write_buf.get(), write_buf->size(), write_callback_.callback())); | 1252 write_buf.get(), write_buf->size(), write_callback_.callback())); |
1253 | 1253 |
1254 ResumeAndRun(); | 1254 ResumeAndRun(); |
1255 | 1255 |
1256 EXPECT_TRUE(sock_.get()); | 1256 EXPECT_TRUE(sock_.get()); |
1257 EXPECT_TRUE(read_callback_.have_result()); | 1257 EXPECT_TRUE(read_callback_.have_result()); |
1258 EXPECT_TRUE(write_callback_.have_result()); | 1258 EXPECT_TRUE(write_callback_.have_result()); |
1259 | 1259 |
1260 // Let the RST_STREAM write while |rst| is in-scope. | 1260 // Let the RST_STREAM write while |rst| is in-scope. |
1261 base::MessageLoop::current()->RunUntilIdle(); | 1261 base::RunLoop().RunUntilIdle(); |
1262 } | 1262 } |
1263 | 1263 |
1264 // Makes sure the proxy client socket's source gets the expected NetLog events | 1264 // Makes sure the proxy client socket's source gets the expected NetLog events |
1265 // and only the expected NetLog events (No SpdySession events). | 1265 // and only the expected NetLog events (No SpdySession events). |
1266 TEST_P(SpdyProxyClientSocketTest, NetLog) { | 1266 TEST_P(SpdyProxyClientSocketTest, NetLog) { |
1267 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 1267 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
1268 std::unique_ptr<SpdySerializedFrame> rst( | 1268 std::unique_ptr<SpdySerializedFrame> rst( |
1269 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 1269 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
1270 MockWrite writes[] = { | 1270 MockWrite writes[] = { |
1271 CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 5), | 1271 CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 5), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 1310 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
1311 NetLog::PHASE_NONE)); | 1311 NetLog::PHASE_NONE)); |
1312 EXPECT_TRUE(LogContainsEndEvent(entry_list, 7, | 1312 EXPECT_TRUE(LogContainsEndEvent(entry_list, 7, |
1313 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS)); | 1313 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS)); |
1314 EXPECT_TRUE(LogContainsEvent(entry_list, 8, | 1314 EXPECT_TRUE(LogContainsEvent(entry_list, 8, |
1315 NetLog::TYPE_SOCKET_BYTES_RECEIVED, | 1315 NetLog::TYPE_SOCKET_BYTES_RECEIVED, |
1316 NetLog::PHASE_NONE)); | 1316 NetLog::PHASE_NONE)); |
1317 EXPECT_TRUE(LogContainsEndEvent(entry_list, 9, NetLog::TYPE_SOCKET_ALIVE)); | 1317 EXPECT_TRUE(LogContainsEndEvent(entry_list, 9, NetLog::TYPE_SOCKET_ALIVE)); |
1318 | 1318 |
1319 // Let the RST_STREAM write while |rst| is in-scope. | 1319 // Let the RST_STREAM write while |rst| is in-scope. |
1320 base::MessageLoop::current()->RunUntilIdle(); | 1320 base::RunLoop().RunUntilIdle(); |
1321 } | 1321 } |
1322 | 1322 |
1323 // CompletionCallback that causes the SpdyProxyClientSocket to be | 1323 // CompletionCallback that causes the SpdyProxyClientSocket to be |
1324 // deleted when Run is invoked. | 1324 // deleted when Run is invoked. |
1325 class DeleteSockCallback : public TestCompletionCallbackBase { | 1325 class DeleteSockCallback : public TestCompletionCallbackBase { |
1326 public: | 1326 public: |
1327 explicit DeleteSockCallback(std::unique_ptr<SpdyProxyClientSocket>* sock) | 1327 explicit DeleteSockCallback(std::unique_ptr<SpdyProxyClientSocket>* sock) |
1328 : sock_(sock), | 1328 : sock_(sock), |
1329 callback_(base::Bind(&DeleteSockCallback::OnComplete, | 1329 callback_(base::Bind(&DeleteSockCallback::OnComplete, |
1330 base::Unretained(this))) {} | 1330 base::Unretained(this))) {} |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 sock_->Write( | 1380 sock_->Write( |
1381 write_buf.get(), write_buf->size(), write_callback_.callback())); | 1381 write_buf.get(), write_buf->size(), write_callback_.callback())); |
1382 | 1382 |
1383 ResumeAndRun(); | 1383 ResumeAndRun(); |
1384 | 1384 |
1385 EXPECT_FALSE(sock_.get()); | 1385 EXPECT_FALSE(sock_.get()); |
1386 EXPECT_TRUE(read_callback.have_result()); | 1386 EXPECT_TRUE(read_callback.have_result()); |
1387 EXPECT_FALSE(write_callback_.have_result()); | 1387 EXPECT_FALSE(write_callback_.have_result()); |
1388 | 1388 |
1389 // Let the RST_STREAM write while |rst| is in-scope. | 1389 // Let the RST_STREAM write while |rst| is in-scope. |
1390 base::MessageLoop::current()->RunUntilIdle(); | 1390 base::RunLoop().RunUntilIdle(); |
1391 } | 1391 } |
1392 | 1392 |
1393 } // namespace net | 1393 } // namespace net |
OLD | NEW |