Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: net/socket/socks_client_socket_unittest.cc

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed implementation of attach/detach of request Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return std::unique_ptr<SOCKSClientSocket>(new SOCKSClientSocket( 97 return std::unique_ptr<SOCKSClientSocket>(new SOCKSClientSocket(
98 std::move(connection), 98 std::move(connection),
99 HostResolver::RequestInfo(HostPortPair(hostname, port)), DEFAULT_PRIORITY, 99 HostResolver::RequestInfo(HostPortPair(hostname, port)), DEFAULT_PRIORITY,
100 host_resolver)); 100 host_resolver));
101 } 101 }
102 102
103 // Implementation of HostResolver that never completes its resolve request. 103 // Implementation of HostResolver that never completes its resolve request.
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 private:
108 class RequestImpl;
mmenke 2016/07/19 19:03:56 Can't have a private section before the public sec
maksims (do not use this acc) 2016/07/21 07:12:46 Done.
109
107 public: 110 public:
108 HangingHostResolverWithCancel() : outstanding_request_(NULL) {} 111 HangingHostResolverWithCancel() : outstanding_request_(NULL) {}
109 112
110 int Resolve(const RequestInfo& info, 113 int Resolve(const RequestInfo& info,
111 RequestPriority priority, 114 RequestPriority priority,
112 AddressList* addresses, 115 AddressList* addresses,
113 const CompletionCallback& callback, 116 const CompletionCallback& callback,
114 RequestHandle* out_req, 117 std::unique_ptr<Request>* out_req,
115 const BoundNetLog& net_log) override { 118 const BoundNetLog& net_log) override {
116 DCHECK(addresses); 119 DCHECK(addresses);
117 DCHECK_EQ(false, callback.is_null()); 120 DCHECK_EQ(false, callback.is_null());
118 EXPECT_FALSE(HasOutstandingRequest()); 121 EXPECT_FALSE(HasOutstandingRequest());
119 outstanding_request_ = reinterpret_cast<RequestHandle>(1); 122 outstanding_request_ = new RequestImpl(this);
120 *out_req = outstanding_request_; 123 (*out_req).reset(outstanding_request_);
mmenke 2016/07/19 19:03:56 out_req->reset
maksims (do not use this acc) 2016/07/21 07:12:46 Done.
121 return ERR_IO_PENDING; 124 return ERR_IO_PENDING;
122 } 125 }
123 126
124 int ResolveFromCache(const RequestInfo& info, 127 int ResolveFromCache(const RequestInfo& info,
125 AddressList* addresses, 128 AddressList* addresses,
126 const BoundNetLog& net_log) override { 129 const BoundNetLog& net_log) override {
127 NOTIMPLEMENTED(); 130 NOTIMPLEMENTED();
128 return ERR_UNEXPECTED; 131 return ERR_UNEXPECTED;
129 } 132 }
130 133
131 void CancelRequest(RequestHandle req) override { 134 void RemoveRequest(RequestImpl* req) {
132 EXPECT_TRUE(HasOutstandingRequest()); 135 EXPECT_TRUE(HasOutstandingRequest());
133 EXPECT_EQ(outstanding_request_, req); 136 EXPECT_EQ(outstanding_request_, req);
134 outstanding_request_ = NULL; 137 outstanding_request_ = nullptr;
135 } 138 }
136 139
137 bool HasOutstandingRequest() { 140 bool HasOutstandingRequest() { return outstanding_request_ != nullptr; }
138 return outstanding_request_ != NULL;
139 }
140 141
141 private: 142 private:
142 RequestHandle outstanding_request_; 143 class RequestImpl : public HostResolver::Request {
144 public:
145 RequestImpl(HangingHostResolverWithCancel* resolver)
146 : resolver_(resolver) {}
147 ~RequestImpl() override {
148 DCHECK(resolver_);
149 resolver_->RemoveRequest(this);
150 }
151
152 void ChangeRequestPriority(RequestPriority priority) override {}
153
154 private:
155 HangingHostResolverWithCancel* resolver_;
156 };
157
158 RequestImpl* outstanding_request_;
143 159
144 DISALLOW_COPY_AND_ASSIGN(HangingHostResolverWithCancel); 160 DISALLOW_COPY_AND_ASSIGN(HangingHostResolverWithCancel);
145 }; 161 };
146 162
147 // Tests a complete handshake and the disconnection. 163 // Tests a complete handshake and the disconnection.
148 TEST_F(SOCKSClientSocketTest, CompleteHandshake) { 164 TEST_F(SOCKSClientSocketTest, CompleteHandshake) {
149 const std::string payload_write = "random data"; 165 const std::string payload_write = "random data";
150 const std::string payload_read = "moar random data"; 166 const std::string payload_read = "moar random data";
151 167
152 MockWrite data_writes[] = { 168 MockWrite data_writes[] = {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 NULL, 0, 468 NULL, 0,
453 host_resolver.get(), 469 host_resolver.get(),
454 kHostName, 80, 470 kHostName, 80,
455 NULL); 471 NULL);
456 472
457 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, 473 EXPECT_EQ(ERR_NAME_NOT_RESOLVED,
458 callback_.GetResult(user_sock_->Connect(callback_.callback()))); 474 callback_.GetResult(user_sock_->Connect(callback_.callback())));
459 } 475 }
460 476
461 } // namespace net 477 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698