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

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: 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
121 return ERR_IO_PENDING; 122 return ERR_IO_PENDING;
122 } 123 }
123 124
124 int ResolveFromCache(const RequestInfo& info, 125 int ResolveFromCache(const RequestInfo& info,
125 AddressList* addresses, 126 AddressList* addresses,
126 const BoundNetLog& net_log) override { 127 const BoundNetLog& net_log) override {
127 NOTIMPLEMENTED(); 128 NOTIMPLEMENTED();
128 return ERR_UNEXPECTED; 129 return ERR_UNEXPECTED;
129 } 130 }
130 131
131 void CancelRequest(RequestHandle req) override {
132 EXPECT_TRUE(HasOutstandingRequest());
133 EXPECT_EQ(outstanding_request_, req);
134 outstanding_request_ = NULL;
135 }
136
137 bool HasOutstandingRequest() { 132 bool HasOutstandingRequest() {
138 return outstanding_request_ != NULL; 133 return outstanding_request_ != NULL;
139 } 134 }
140 135
141 private: 136 private:
142 RequestHandle outstanding_request_; 137 class RequestImpl : public HostResolver::Request {
138 public:
139 explicit RequestImpl(HangingHostResolverWithCancel* resolver)
140 : resolver_(resolver) {}
141
142 ~RequestImpl() override {
143 if (resolver_) {
144 EXPECT_TRUE(resolver_->HasOutstandingRequest());
145 EXPECT_EQ(resolver_->outstanding_request_, this);
146 resolver_->outstanding_request_ = nullptr;
147 }
148 }
149
150 void ChangeRequestPriority(RequestPriority priority) override {}
151
152 void RemoveResolver() { resolver_ = nullptr; }
153
154 private:
155 HangingHostResolverWithCancel* resolver_;
156
157 DISALLOW_COPY_AND_ASSIGN(RequestImpl);
158 };
159
160 friend RequestImpl;
161
162 RequestImpl* outstanding_request_;
143 163
144 DISALLOW_COPY_AND_ASSIGN(HangingHostResolverWithCancel); 164 DISALLOW_COPY_AND_ASSIGN(HangingHostResolverWithCancel);
145 }; 165 };
146 166
147 // Tests a complete handshake and the disconnection. 167 // Tests a complete handshake and the disconnection.
148 TEST_F(SOCKSClientSocketTest, CompleteHandshake) { 168 TEST_F(SOCKSClientSocketTest, CompleteHandshake) {
149 const std::string payload_write = "random data"; 169 const std::string payload_write = "random data";
150 const std::string payload_read = "moar random data"; 170 const std::string payload_read = "moar random data";
151 171
152 MockWrite data_writes[] = { 172 MockWrite data_writes[] = {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 NULL, 0, 472 NULL, 0,
453 host_resolver.get(), 473 host_resolver.get(),
454 kHostName, 80, 474 kHostName, 80,
455 NULL); 475 NULL);
456 476
457 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, 477 EXPECT_EQ(ERR_NAME_NOT_RESOLVED,
458 callback_.GetResult(user_sock_->Connect(callback_.callback()))); 478 callback_.GetResult(user_sock_->Connect(callback_.callback())));
459 } 479 }
460 480
461 } // namespace net 481 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698