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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "net/log/test_net_log_util.h" | 23 #include "net/log/test_net_log_util.h" |
24 #include "net/socket/client_socket_factory.h" | 24 #include "net/socket/client_socket_factory.h" |
25 #include "net/socket/next_proto.h" | 25 #include "net/socket/next_proto.h" |
26 #include "net/socket/socket_test_util.h" | 26 #include "net/socket/socket_test_util.h" |
27 #include "net/socket/tcp_client_socket.h" | 27 #include "net/socket/tcp_client_socket.h" |
28 #include "net/spdy/buffered_spdy_framer.h" | 28 #include "net/spdy/buffered_spdy_framer.h" |
29 #include "net/spdy/spdy_http_utils.h" | 29 #include "net/spdy/spdy_http_utils.h" |
30 #include "net/spdy/spdy_protocol.h" | 30 #include "net/spdy/spdy_protocol.h" |
31 #include "net/spdy/spdy_session_pool.h" | 31 #include "net/spdy/spdy_session_pool.h" |
32 #include "net/spdy/spdy_test_util_common.h" | 32 #include "net/spdy/spdy_test_util_common.h" |
| 33 #include "net/test/gtest_util.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "testing/platform_test.h" | 36 #include "testing/platform_test.h" |
35 | 37 |
| 38 using net::test::IsError; |
| 39 using net::test::IsOk; |
| 40 |
36 //----------------------------------------------------------------------------- | 41 //----------------------------------------------------------------------------- |
37 | 42 |
38 namespace { | 43 namespace { |
39 | 44 |
40 enum TestCase { | 45 enum TestCase { |
41 // Test using the SPDY/3.1 protocol. | 46 // Test using the SPDY/3.1 protocol. |
42 kTestCaseSPDY31, | 47 kTestCaseSPDY31, |
43 | 48 |
44 // Test using the HTTP/2 protocol, without specifying a stream | 49 // Test using the HTTP/2 protocol, without specifying a stream |
45 // dependency based on the RequestPriority. | 50 // dependency based on the RequestPriority. |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 243 } |
239 | 244 |
240 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( | 245 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( |
241 const char* data, int size) { | 246 const char* data, int size) { |
242 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); | 247 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); |
243 memcpy(buf->data(), data, size); | 248 memcpy(buf->data(), data, size); |
244 return buf; | 249 return buf; |
245 } | 250 } |
246 | 251 |
247 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { | 252 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { |
248 ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); | 253 ASSERT_THAT(sock_->Connect(read_callback_.callback()), |
249 ASSERT_EQ(OK, read_callback_.WaitForResult()); | 254 IsError(ERR_IO_PENDING)); |
| 255 ASSERT_THAT(read_callback_.WaitForResult(), IsOk()); |
250 } | 256 } |
251 | 257 |
252 void SpdyProxyClientSocketTest::AssertConnectFails(int result) { | 258 void SpdyProxyClientSocketTest::AssertConnectFails(int result) { |
253 ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); | 259 ASSERT_THAT(sock_->Connect(read_callback_.callback()), |
| 260 IsError(ERR_IO_PENDING)); |
254 ASSERT_EQ(result, read_callback_.WaitForResult()); | 261 ASSERT_EQ(result, read_callback_.WaitForResult()); |
255 } | 262 } |
256 | 263 |
257 void SpdyProxyClientSocketTest::AssertConnectionEstablished() { | 264 void SpdyProxyClientSocketTest::AssertConnectionEstablished() { |
258 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | 265 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
259 ASSERT_TRUE(response != NULL); | 266 ASSERT_TRUE(response != NULL); |
260 ASSERT_EQ(200, response->headers->response_code()); | 267 ASSERT_EQ(200, response->headers->response_code()); |
261 } | 268 } |
262 | 269 |
263 void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data, | 270 void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data, |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 555 |
549 std::unique_ptr<SpdySerializedFrame> resp(ConstructConnectReplyFrame()); | 556 std::unique_ptr<SpdySerializedFrame> resp(ConstructConnectReplyFrame()); |
550 MockRead reads[] = { | 557 MockRead reads[] = { |
551 CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), | 558 CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, ERR_IO_PENDING, 2), |
552 MockRead(ASYNC, 0, 3), // EOF | 559 MockRead(ASYNC, 0, 3), // EOF |
553 }; | 560 }; |
554 | 561 |
555 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 562 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
556 | 563 |
557 IPEndPoint addr; | 564 IPEndPoint addr; |
558 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 565 EXPECT_THAT(sock_->GetPeerAddress(&addr), IsError(ERR_SOCKET_NOT_CONNECTED)); |
559 | 566 |
560 AssertConnectSucceeds(); | 567 AssertConnectSucceeds(); |
561 EXPECT_TRUE(sock_->IsConnected()); | 568 EXPECT_TRUE(sock_->IsConnected()); |
562 EXPECT_EQ(OK, sock_->GetPeerAddress(&addr)); | 569 EXPECT_THAT(sock_->GetPeerAddress(&addr), IsOk()); |
563 | 570 |
564 ResumeAndRun(); | 571 ResumeAndRun(); |
565 | 572 |
566 EXPECT_FALSE(sock_->IsConnected()); | 573 EXPECT_FALSE(sock_->IsConnected()); |
567 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 574 EXPECT_THAT(sock_->GetPeerAddress(&addr), IsError(ERR_SOCKET_NOT_CONNECTED)); |
568 | 575 |
569 sock_->Disconnect(); | 576 sock_->Disconnect(); |
570 | 577 |
571 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 578 EXPECT_THAT(sock_->GetPeerAddress(&addr), IsError(ERR_SOCKET_NOT_CONNECTED)); |
572 } | 579 } |
573 | 580 |
574 // ----------- Write | 581 // ----------- Write |
575 | 582 |
576 TEST_P(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) { | 583 TEST_P(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) { |
577 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 584 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
578 std::unique_ptr<SpdySerializedFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 585 std::unique_ptr<SpdySerializedFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
579 std::unique_ptr<SpdySerializedFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 586 std::unique_ptr<SpdySerializedFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
580 MockWrite writes[] = { | 587 MockWrite writes[] = { |
581 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 588 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 EXPECT_TRUE(sock_->IsConnected()); | 1151 EXPECT_TRUE(sock_->IsConnected()); |
1145 | 1152 |
1146 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1153 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1147 EXPECT_EQ(ERR_IO_PENDING, | 1154 EXPECT_EQ(ERR_IO_PENDING, |
1148 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); | 1155 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); |
1149 // Make sure the write actually starts. | 1156 // Make sure the write actually starts. |
1150 base::RunLoop().RunUntilIdle(); | 1157 base::RunLoop().RunUntilIdle(); |
1151 | 1158 |
1152 CloseSpdySession(ERR_ABORTED, std::string()); | 1159 CloseSpdySession(ERR_ABORTED, std::string()); |
1153 | 1160 |
1154 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); | 1161 EXPECT_THAT(write_callback_.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
1155 } | 1162 } |
1156 | 1163 |
1157 // If the socket is Disconnected with a pending Write(), the callback | 1164 // If the socket is Disconnected with a pending Write(), the callback |
1158 // should not be called. | 1165 // should not be called. |
1159 TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) { | 1166 TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) { |
1160 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); | 1167 std::unique_ptr<SpdySerializedFrame> conn(ConstructConnectRequestFrame()); |
1161 std::unique_ptr<SpdySerializedFrame> rst( | 1168 std::unique_ptr<SpdySerializedFrame> rst( |
1162 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 1169 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
1163 MockWrite writes[] = { | 1170 MockWrite writes[] = { |
1164 CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), | 1171 CreateMockWrite(*conn, 0, SYNCHRONOUS), CreateMockWrite(*rst, 3), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 | 1394 |
1388 EXPECT_FALSE(sock_.get()); | 1395 EXPECT_FALSE(sock_.get()); |
1389 EXPECT_TRUE(read_callback.have_result()); | 1396 EXPECT_TRUE(read_callback.have_result()); |
1390 EXPECT_FALSE(write_callback_.have_result()); | 1397 EXPECT_FALSE(write_callback_.have_result()); |
1391 | 1398 |
1392 // Let the RST_STREAM write while |rst| is in-scope. | 1399 // Let the RST_STREAM write while |rst| is in-scope. |
1393 base::RunLoop().RunUntilIdle(); | 1400 base::RunLoop().RunUntilIdle(); |
1394 } | 1401 } |
1395 | 1402 |
1396 } // namespace net | 1403 } // namespace net |
OLD | NEW |