Chromium Code Reviews| 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/socks5_client_socket.h" | 5 #include "net/socket/socks5_client_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 int port, | 40 int port, |
| 41 NetLog* net_log); | 41 NetLog* net_log); |
| 42 | 42 |
| 43 virtual void SetUp(); | 43 virtual void SetUp(); |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 const uint16 kNwPort; | 46 const uint16 kNwPort; |
| 47 CapturingNetLog net_log_; | 47 CapturingNetLog net_log_; |
| 48 scoped_ptr<SOCKS5ClientSocket> user_sock_; | 48 scoped_ptr<SOCKS5ClientSocket> user_sock_; |
| 49 AddressList address_list_; | 49 AddressList address_list_; |
| 50 // Filled in by BuildMockSocket() and owned by its return value | |
| 51 // (which |user_sock| is set to). | |
| 50 StreamSocket* tcp_sock_; | 52 StreamSocket* tcp_sock_; |
| 51 TestCompletionCallback callback_; | 53 TestCompletionCallback callback_; |
| 52 scoped_ptr<MockHostResolver> host_resolver_; | 54 scoped_ptr<MockHostResolver> host_resolver_; |
| 53 scoped_ptr<SocketDataProvider> data_; | 55 scoped_ptr<SocketDataProvider> data_; |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(SOCKS5ClientSocketTest); | 58 DISALLOW_COPY_AND_ASSIGN(SOCKS5ClientSocketTest); |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 SOCKS5ClientSocketTest::SOCKS5ClientSocketTest() | 61 SOCKS5ClientSocketTest::SOCKS5ClientSocketTest() |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 87 data_.reset(new StaticSocketDataProvider(reads, reads_count, | 89 data_.reset(new StaticSocketDataProvider(reads, reads_count, |
| 88 writes, writes_count)); | 90 writes, writes_count)); |
| 89 tcp_sock_ = new MockTCPClientSocket(address_list_, net_log, data_.get()); | 91 tcp_sock_ = new MockTCPClientSocket(address_list_, net_log, data_.get()); |
| 90 | 92 |
| 91 int rv = tcp_sock_->Connect(callback.callback()); | 93 int rv = tcp_sock_->Connect(callback.callback()); |
| 92 EXPECT_EQ(ERR_IO_PENDING, rv); | 94 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 93 rv = callback.WaitForResult(); | 95 rv = callback.WaitForResult(); |
| 94 EXPECT_EQ(OK, rv); | 96 EXPECT_EQ(OK, rv); |
| 95 EXPECT_TRUE(tcp_sock_->IsConnected()); | 97 EXPECT_TRUE(tcp_sock_->IsConnected()); |
| 96 | 98 |
| 97 return new SOCKS5ClientSocket(tcp_sock_, | 99 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 100 // |connection| takes ownership of |tcp_sock_|, but we still keep a | |
| 101 // non-owning pointer to it. | |
|
Ryan Sleevi
2013/08/13 20:26:13
comment nit: s/we still//
https://groups.google.c
akalin
2013/08/13 20:51:28
Done.
| |
| 102 connection->set_socket(tcp_sock_); | |
| 103 return new SOCKS5ClientSocket(connection.release(), | |
|
Ryan Sleevi
2013/08/13 20:26:13
style nit: connection.release() should be on a new
akalin
2013/08/13 20:51:28
Done.
| |
| 98 HostResolver::RequestInfo(HostPortPair(hostname, port))); | 104 HostResolver::RequestInfo(HostPortPair(hostname, port))); |
| 99 } | 105 } |
| 100 | 106 |
| 101 // Tests a complete SOCKS5 handshake and the disconnection. | 107 // Tests a complete SOCKS5 handshake and the disconnection. |
| 102 TEST_F(SOCKS5ClientSocketTest, CompleteHandshake) { | 108 TEST_F(SOCKS5ClientSocketTest, CompleteHandshake) { |
| 103 const std::string payload_write = "random data"; | 109 const std::string payload_write = "random data"; |
| 104 const std::string payload_read = "moar random data"; | 110 const std::string payload_read = "moar random data"; |
| 105 | 111 |
| 106 const char kOkRequest[] = { | 112 const char kOkRequest[] = { |
| 107 0x05, // Version | 113 0x05, // Version |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 EXPECT_TRUE(user_sock_->IsConnected()); | 365 EXPECT_TRUE(user_sock_->IsConnected()); |
| 360 net_log_.GetEntries(&net_log_entries); | 366 net_log_.GetEntries(&net_log_entries); |
| 361 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1, | 367 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1, |
| 362 NetLog::TYPE_SOCKS5_CONNECT)); | 368 NetLog::TYPE_SOCKS5_CONNECT)); |
| 363 } | 369 } |
| 364 } | 370 } |
| 365 | 371 |
| 366 } // namespace | 372 } // namespace |
| 367 | 373 |
| 368 } // namespace net | 374 } // namespace net |
| OLD | NEW |