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/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 } | 850 } |
851 | 851 |
852 MockTCPClientSocket::~MockTCPClientSocket() {} | 852 MockTCPClientSocket::~MockTCPClientSocket() {} |
853 | 853 |
854 int MockTCPClientSocket::Read(IOBuffer* buf, int buf_len, | 854 int MockTCPClientSocket::Read(IOBuffer* buf, int buf_len, |
855 const CompletionCallback& callback) { | 855 const CompletionCallback& callback) { |
856 if (!connected_) | 856 if (!connected_) |
857 return ERR_UNEXPECTED; | 857 return ERR_UNEXPECTED; |
858 | 858 |
859 // If the buffer is already in use, a read is already in progress! | 859 // If the buffer is already in use, a read is already in progress! |
860 DCHECK(pending_buf_ == NULL); | 860 DCHECK(pending_buf_.get() == NULL); |
861 | 861 |
862 // Store our async IO data. | 862 // Store our async IO data. |
863 pending_buf_ = buf; | 863 pending_buf_ = buf; |
864 pending_buf_len_ = buf_len; | 864 pending_buf_len_ = buf_len; |
865 pending_callback_ = callback; | 865 pending_callback_ = callback; |
866 | 866 |
867 if (need_read_data_) { | 867 if (need_read_data_) { |
868 read_data_ = data_->GetNextRead(); | 868 read_data_ = data_->GetNextRead(); |
869 if (read_data_.result == ERR_CONNECTION_CLOSED) { | 869 if (read_data_.result == ERR_CONNECTION_CLOSED) { |
870 // This MockRead is just a marker to instruct us to set | 870 // This MockRead is just a marker to instruct us to set |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 bool MockTCPClientSocket::WasNpnNegotiated() const { | 958 bool MockTCPClientSocket::WasNpnNegotiated() const { |
959 return false; | 959 return false; |
960 } | 960 } |
961 | 961 |
962 bool MockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { | 962 bool MockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { |
963 return false; | 963 return false; |
964 } | 964 } |
965 | 965 |
966 void MockTCPClientSocket::OnReadComplete(const MockRead& data) { | 966 void MockTCPClientSocket::OnReadComplete(const MockRead& data) { |
967 // There must be a read pending. | 967 // There must be a read pending. |
968 DCHECK(pending_buf_); | 968 DCHECK(pending_buf_.get()); |
969 // You can't complete a read with another ERR_IO_PENDING status code. | 969 // You can't complete a read with another ERR_IO_PENDING status code. |
970 DCHECK_NE(ERR_IO_PENDING, data.result); | 970 DCHECK_NE(ERR_IO_PENDING, data.result); |
971 // Since we've been waiting for data, need_read_data_ should be true. | 971 // Since we've been waiting for data, need_read_data_ should be true. |
972 DCHECK(need_read_data_); | 972 DCHECK(need_read_data_); |
973 | 973 |
974 read_data_ = data; | 974 read_data_ = data; |
975 need_read_data_ = false; | 975 need_read_data_ = false; |
976 | 976 |
977 // The caller is simulating that this IO completes right now. Don't | 977 // The caller is simulating that this IO completes right now. Don't |
978 // let CompleteRead() schedule a callback. | 978 // let CompleteRead() schedule a callback. |
979 read_data_.mode = SYNCHRONOUS; | 979 read_data_.mode = SYNCHRONOUS; |
980 | 980 |
981 CompletionCallback callback = pending_callback_; | 981 CompletionCallback callback = pending_callback_; |
982 int rv = CompleteRead(); | 982 int rv = CompleteRead(); |
983 RunCallback(callback, rv); | 983 RunCallback(callback, rv); |
984 } | 984 } |
985 | 985 |
986 void MockTCPClientSocket::OnConnectComplete(const MockConnect& data) { | 986 void MockTCPClientSocket::OnConnectComplete(const MockConnect& data) { |
987 CompletionCallback callback = pending_callback_; | 987 CompletionCallback callback = pending_callback_; |
988 RunCallback(callback, data.result); | 988 RunCallback(callback, data.result); |
989 } | 989 } |
990 | 990 |
991 int MockTCPClientSocket::CompleteRead() { | 991 int MockTCPClientSocket::CompleteRead() { |
992 DCHECK(pending_buf_); | 992 DCHECK(pending_buf_.get()); |
993 DCHECK(pending_buf_len_ > 0); | 993 DCHECK(pending_buf_len_ > 0); |
994 | 994 |
995 was_used_to_convey_data_ = true; | 995 was_used_to_convey_data_ = true; |
996 | 996 |
997 // Save the pending async IO data and reset our |pending_| state. | 997 // Save the pending async IO data and reset our |pending_| state. |
998 scoped_refptr<IOBuffer> buf = pending_buf_; | 998 scoped_refptr<IOBuffer> buf = pending_buf_; |
999 int buf_len = pending_buf_len_; | 999 int buf_len = pending_buf_len_; |
1000 CompletionCallback callback = pending_callback_; | 1000 CompletionCallback callback = pending_callback_; |
1001 pending_buf_ = NULL; | 1001 pending_buf_ = NULL; |
1002 pending_buf_len_ = 0; | 1002 pending_buf_len_ = 0; |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 | 1553 |
1554 MockUDPClientSocket::~MockUDPClientSocket() {} | 1554 MockUDPClientSocket::~MockUDPClientSocket() {} |
1555 | 1555 |
1556 int MockUDPClientSocket::Read(IOBuffer* buf, | 1556 int MockUDPClientSocket::Read(IOBuffer* buf, |
1557 int buf_len, | 1557 int buf_len, |
1558 const CompletionCallback& callback) { | 1558 const CompletionCallback& callback) { |
1559 if (!connected_) | 1559 if (!connected_) |
1560 return ERR_UNEXPECTED; | 1560 return ERR_UNEXPECTED; |
1561 | 1561 |
1562 // If the buffer is already in use, a read is already in progress! | 1562 // If the buffer is already in use, a read is already in progress! |
1563 DCHECK(pending_buf_ == NULL); | 1563 DCHECK(pending_buf_.get() == NULL); |
1564 | 1564 |
1565 // Store our async IO data. | 1565 // Store our async IO data. |
1566 pending_buf_ = buf; | 1566 pending_buf_ = buf; |
1567 pending_buf_len_ = buf_len; | 1567 pending_buf_len_ = buf_len; |
1568 pending_callback_ = callback; | 1568 pending_callback_ = callback; |
1569 | 1569 |
1570 if (need_read_data_) { | 1570 if (need_read_data_) { |
1571 read_data_ = data_->GetNextRead(); | 1571 read_data_ = data_->GetNextRead(); |
1572 // ERR_IO_PENDING means that the SocketDataProvider is taking responsibility | 1572 // ERR_IO_PENDING means that the SocketDataProvider is taking responsibility |
1573 // to complete the async IO manually later (via OnReadComplete). | 1573 // to complete the async IO manually later (via OnReadComplete). |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 } | 1630 } |
1631 | 1631 |
1632 int MockUDPClientSocket::Connect(const IPEndPoint& address) { | 1632 int MockUDPClientSocket::Connect(const IPEndPoint& address) { |
1633 connected_ = true; | 1633 connected_ = true; |
1634 peer_addr_ = address; | 1634 peer_addr_ = address; |
1635 return data_->connect_data().result; | 1635 return data_->connect_data().result; |
1636 } | 1636 } |
1637 | 1637 |
1638 void MockUDPClientSocket::OnReadComplete(const MockRead& data) { | 1638 void MockUDPClientSocket::OnReadComplete(const MockRead& data) { |
1639 // There must be a read pending. | 1639 // There must be a read pending. |
1640 DCHECK(pending_buf_); | 1640 DCHECK(pending_buf_.get()); |
1641 // You can't complete a read with another ERR_IO_PENDING status code. | 1641 // You can't complete a read with another ERR_IO_PENDING status code. |
1642 DCHECK_NE(ERR_IO_PENDING, data.result); | 1642 DCHECK_NE(ERR_IO_PENDING, data.result); |
1643 // Since we've been waiting for data, need_read_data_ should be true. | 1643 // Since we've been waiting for data, need_read_data_ should be true. |
1644 DCHECK(need_read_data_); | 1644 DCHECK(need_read_data_); |
1645 | 1645 |
1646 read_data_ = data; | 1646 read_data_ = data; |
1647 need_read_data_ = false; | 1647 need_read_data_ = false; |
1648 | 1648 |
1649 // The caller is simulating that this IO completes right now. Don't | 1649 // The caller is simulating that this IO completes right now. Don't |
1650 // let CompleteRead() schedule a callback. | 1650 // let CompleteRead() schedule a callback. |
1651 read_data_.mode = SYNCHRONOUS; | 1651 read_data_.mode = SYNCHRONOUS; |
1652 | 1652 |
1653 net::CompletionCallback callback = pending_callback_; | 1653 net::CompletionCallback callback = pending_callback_; |
1654 int rv = CompleteRead(); | 1654 int rv = CompleteRead(); |
1655 RunCallback(callback, rv); | 1655 RunCallback(callback, rv); |
1656 } | 1656 } |
1657 | 1657 |
1658 void MockUDPClientSocket::OnConnectComplete(const MockConnect& data) { | 1658 void MockUDPClientSocket::OnConnectComplete(const MockConnect& data) { |
1659 NOTIMPLEMENTED(); | 1659 NOTIMPLEMENTED(); |
1660 } | 1660 } |
1661 | 1661 |
1662 int MockUDPClientSocket::CompleteRead() { | 1662 int MockUDPClientSocket::CompleteRead() { |
1663 DCHECK(pending_buf_); | 1663 DCHECK(pending_buf_.get()); |
1664 DCHECK(pending_buf_len_ > 0); | 1664 DCHECK(pending_buf_len_ > 0); |
1665 | 1665 |
1666 // Save the pending async IO data and reset our |pending_| state. | 1666 // Save the pending async IO data and reset our |pending_| state. |
1667 scoped_refptr<IOBuffer> buf = pending_buf_; | 1667 scoped_refptr<IOBuffer> buf = pending_buf_; |
1668 int buf_len = pending_buf_len_; | 1668 int buf_len = pending_buf_len_; |
1669 CompletionCallback callback = pending_callback_; | 1669 CompletionCallback callback = pending_callback_; |
1670 pending_buf_ = NULL; | 1670 pending_buf_ = NULL; |
1671 pending_buf_len_ = 0; | 1671 pending_buf_len_ = 0; |
1672 pending_callback_.Reset(); | 1672 pending_callback_.Reset(); |
1673 | 1673 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 | 1991 |
1992 const char kSOCKS5OkRequest[] = | 1992 const char kSOCKS5OkRequest[] = |
1993 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1993 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
1994 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1994 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
1995 | 1995 |
1996 const char kSOCKS5OkResponse[] = | 1996 const char kSOCKS5OkResponse[] = |
1997 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1997 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
1998 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1998 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
1999 | 1999 |
2000 } // namespace net | 2000 } // namespace net |
OLD | NEW |