OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/socks_client_socket.h" | 5 #include "net/socket/socks_client_socket.h" |
6 | 6 |
7 #include "net/base/address_list.h" | 7 #include "net/base/address_list.h" |
8 #include "net/base/load_log.h" | 8 #include "net/base/load_log.h" |
9 #include "net/base/load_log_unittest.h" | 9 #include "net/base/load_log_unittest.h" |
10 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 virtual void CancelRequest(RequestHandle req) { | 98 virtual void CancelRequest(RequestHandle req) { |
99 EXPECT_TRUE(HasOutstandingRequest()); | 99 EXPECT_TRUE(HasOutstandingRequest()); |
100 EXPECT_EQ(outstanding_request_, req); | 100 EXPECT_EQ(outstanding_request_, req); |
101 outstanding_request_ = NULL; | 101 outstanding_request_ = NULL; |
102 } | 102 } |
103 | 103 |
104 virtual void AddObserver(Observer* observer) {} | 104 virtual void AddObserver(Observer* observer) {} |
105 virtual void RemoveObserver(Observer* observer) {} | 105 virtual void RemoveObserver(Observer* observer) {} |
106 virtual void Shutdown() {} | |
107 | 106 |
108 bool HasOutstandingRequest() { | 107 bool HasOutstandingRequest() { |
109 return outstanding_request_ != NULL; | 108 return outstanding_request_ != NULL; |
110 } | 109 } |
111 | 110 |
112 private: | 111 private: |
113 RequestHandle outstanding_request_; | 112 RequestHandle outstanding_request_; |
114 | 113 |
115 DISALLOW_COPY_AND_ASSIGN(HangingHostResolver); | 114 DISALLOW_COPY_AND_ASSIGN(HangingHostResolver); |
116 }; | 115 }; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // List of responses from the socks server and the errors they should | 168 // List of responses from the socks server and the errors they should |
170 // throw up are tested here. | 169 // throw up are tested here. |
171 TEST_F(SOCKSClientSocketTest, HandshakeFailures) { | 170 TEST_F(SOCKSClientSocketTest, HandshakeFailures) { |
172 const struct { | 171 const struct { |
173 const char fail_reply[8]; | 172 const char fail_reply[8]; |
174 Error fail_code; | 173 Error fail_code; |
175 } tests[] = { | 174 } tests[] = { |
176 // Failure of the server response code | 175 // Failure of the server response code |
177 { | 176 { |
178 { 0x01, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }, | 177 { 0x01, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }, |
179 ERR_INVALID_RESPONSE, | 178 ERR_SOCKS_CONNECTION_FAILED, |
180 }, | 179 }, |
181 // Failure of the null byte | 180 // Failure of the null byte |
182 { | 181 { |
183 { 0x00, 0x5B, 0x00, 0x00, 0, 0, 0, 0 }, | 182 { 0x00, 0x5B, 0x00, 0x00, 0, 0, 0, 0 }, |
184 ERR_FAILED, | 183 ERR_SOCKS_CONNECTION_FAILED, |
185 }, | 184 }, |
186 }; | 185 }; |
187 | 186 |
188 //--------------------------------------- | 187 //--------------------------------------- |
189 | 188 |
190 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 189 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
191 MockWrite data_writes[] = { | 190 MockWrite data_writes[] = { |
192 MockWrite(false, kSOCKSOkRequest, arraysize(kSOCKSOkRequest)) }; | 191 MockWrite(false, kSOCKSOkRequest, arraysize(kSOCKSOkRequest)) }; |
193 MockRead data_reads[] = { | 192 MockRead data_reads[] = { |
194 MockRead(false, tests[i].fail_reply, arraysize(tests[i].fail_reply)) }; | 193 MockRead(false, tests[i].fail_reply, arraysize(tests[i].fail_reply)) }; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // Disconnect the SOCKS socket -- this should cancel the outstanding resolve. | 370 // Disconnect the SOCKS socket -- this should cancel the outstanding resolve. |
372 user_sock_->Disconnect(); | 371 user_sock_->Disconnect(); |
373 | 372 |
374 EXPECT_FALSE(hanging_resolver->HasOutstandingRequest()); | 373 EXPECT_FALSE(hanging_resolver->HasOutstandingRequest()); |
375 | 374 |
376 EXPECT_FALSE(user_sock_->IsConnected()); | 375 EXPECT_FALSE(user_sock_->IsConnected()); |
377 EXPECT_FALSE(user_sock_->IsConnectedAndIdle()); | 376 EXPECT_FALSE(user_sock_->IsConnectedAndIdle()); |
378 } | 377 } |
379 | 378 |
380 } // namespace net | 379 } // namespace net |
OLD | NEW |