| 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/socks_client_socket.h" | 5 #include "net/socket/socks_client_socket.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // We use this in the test "DisconnectWhileHostResolveInProgress" to make | 104 // We use this in the test "DisconnectWhileHostResolveInProgress" to make |
| 105 // sure that the outstanding resolve request gets cancelled. | 105 // sure that the outstanding resolve request gets cancelled. |
| 106 class HangingHostResolverWithCancel : public HostResolver { | 106 class HangingHostResolverWithCancel : public HostResolver { |
| 107 public: | 107 public: |
| 108 HangingHostResolverWithCancel() : outstanding_request_(NULL) {} | 108 HangingHostResolverWithCancel() : outstanding_request_(NULL) {} |
| 109 | 109 |
| 110 int Resolve(const RequestInfo& info, | 110 int Resolve(const RequestInfo& info, |
| 111 RequestPriority priority, | 111 RequestPriority priority, |
| 112 AddressList* addresses, | 112 AddressList* addresses, |
| 113 const CompletionCallback& callback, | 113 const CompletionCallback& callback, |
| 114 RequestHandle* out_req, | 114 std::unique_ptr<Request>* out_req, |
| 115 const BoundNetLog& net_log) override { | 115 const BoundNetLog& net_log) override { |
| 116 DCHECK(addresses); | 116 DCHECK(addresses); |
| 117 DCHECK_EQ(false, callback.is_null()); | 117 DCHECK_EQ(false, callback.is_null()); |
| 118 EXPECT_FALSE(HasOutstandingRequest()); | 118 EXPECT_FALSE(HasOutstandingRequest()); |
| 119 outstanding_request_ = reinterpret_cast<RequestHandle>(1); | 119 outstanding_request_ = new RequestImpl(this); |
| 120 *out_req = outstanding_request_; | 120 out_req->reset(outstanding_request_); |
| 121 return ERR_IO_PENDING; | 121 return ERR_IO_PENDING; |
| 122 } | 122 } |
| 123 | 123 |
| 124 int ResolveFromCache(const RequestInfo& info, | 124 int ResolveFromCache(const RequestInfo& info, |
| 125 AddressList* addresses, | 125 AddressList* addresses, |
| 126 const BoundNetLog& net_log) override { | 126 const BoundNetLog& net_log) override { |
| 127 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
| 128 return ERR_UNEXPECTED; | 128 return ERR_UNEXPECTED; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void CancelRequest(RequestHandle req) override { | 131 void RemoveRequest(Request* req) { |
| 132 EXPECT_TRUE(HasOutstandingRequest()); | 132 EXPECT_TRUE(HasOutstandingRequest()); |
| 133 EXPECT_EQ(outstanding_request_, req); | 133 EXPECT_EQ(outstanding_request_, req); |
| 134 outstanding_request_ = NULL; | 134 outstanding_request_ = nullptr; |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool HasOutstandingRequest() { | 137 bool HasOutstandingRequest() { return outstanding_request_ != nullptr; } |
| 138 return outstanding_request_ != NULL; | |
| 139 } | |
| 140 | 138 |
| 141 private: | 139 private: |
| 142 RequestHandle outstanding_request_; | 140 class RequestImpl : public HostResolver::Request { |
| 141 public: |
| 142 RequestImpl(HangingHostResolverWithCancel* resolver) |
| 143 : resolver_(resolver) {} |
| 144 ~RequestImpl() override { |
| 145 DCHECK(resolver_); |
| 146 resolver_->RemoveRequest(this); |
| 147 } |
| 148 |
| 149 void ChangeRequestPriority(RequestPriority priority) override {} |
| 150 |
| 151 private: |
| 152 HangingHostResolverWithCancel* resolver_; |
| 153 }; |
| 154 |
| 155 Request* outstanding_request_; |
| 143 | 156 |
| 144 DISALLOW_COPY_AND_ASSIGN(HangingHostResolverWithCancel); | 157 DISALLOW_COPY_AND_ASSIGN(HangingHostResolverWithCancel); |
| 145 }; | 158 }; |
| 146 | 159 |
| 147 // Tests a complete handshake and the disconnection. | 160 // Tests a complete handshake and the disconnection. |
| 148 TEST_F(SOCKSClientSocketTest, CompleteHandshake) { | 161 TEST_F(SOCKSClientSocketTest, CompleteHandshake) { |
| 149 const std::string payload_write = "random data"; | 162 const std::string payload_write = "random data"; |
| 150 const std::string payload_read = "moar random data"; | 163 const std::string payload_read = "moar random data"; |
| 151 | 164 |
| 152 MockWrite data_writes[] = { | 165 MockWrite data_writes[] = { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 NULL, 0, | 465 NULL, 0, |
| 453 host_resolver.get(), | 466 host_resolver.get(), |
| 454 kHostName, 80, | 467 kHostName, 80, |
| 455 NULL); | 468 NULL); |
| 456 | 469 |
| 457 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, | 470 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 458 callback_.GetResult(user_sock_->Connect(callback_.callback()))); | 471 callback_.GetResult(user_sock_->Connect(callback_.callback()))); |
| 459 } | 472 } |
| 460 | 473 |
| 461 } // namespace net | 474 } // namespace net |
| OLD | NEW |