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

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

Issue 155618: Use manually constructed IPv6 socket addresses for tests, rather than system ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 11 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 | Annotate | Revision Log
« no previous file with comments | « net/base/mock_host_resolver.cc ('k') | net/socket/socks_client_socket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/socks5_client_socket.h" 5 #include "net/socket/socks5_client_socket.h"
6 6
7 #include <map> 7 #include <map>
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <ws2tcpip.h> 10 #include <ws2tcpip.h>
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 user_sock_->address_type_); 172 user_sock_->address_type_);
173 } 173 }
174 174
175 // Tries to connect to a domain that resolves to IPv6. 175 // Tries to connect to a domain that resolves to IPv6.
176 TEST_F(SOCKS5ClientSocketTest, IPv6Domain) { 176 TEST_F(SOCKS5ClientSocketTest, IPv6Domain) {
177 const std::string hostname = "an.ipv6.address"; 177 const std::string hostname = "an.ipv6.address";
178 const char kSOCKS5IPv6Request[] = { 0x05, 0x01, 0x00, 0x04 }; 178 const char kSOCKS5IPv6Request[] = { 0x05, 0x01, 0x00, 0x04 };
179 const uint8 ipv6_addr[] = { 0x20, 0x01, 0x0d, 0xb8, 0x87, 0x14, 0x3a, 0x90, 179 const uint8 ipv6_addr[] = { 0x20, 0x01, 0x0d, 0xb8, 0x87, 0x14, 0x3a, 0x90,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x000, 0x00, 0x12 }; 180 0x00, 0x00, 0x00, 0x00, 0x00, 0x000, 0x00, 0x12 };
181 181
182 host_resolver_->rules()->AddRule(hostname, "2001:db8:8714:3a90::12"); 182 host_resolver_->rules()->AddIPv6Rule(hostname, "2001:db8:8714:3a90::12");
183
184 AddressList address_list;
185 HostResolver::RequestInfo info(hostname, 80);
186 int rv = host_resolver_->Resolve(info, &address_list, NULL, NULL);
187 if (rv != OK || !address_list.head()) {
188 // This machine does not support IPv6. We skip this test altogether.
189 // TODO(arindam): create a MockIPv6HostResolver to manually
190 // populate the |address_list| in case of a machine with no IPv6 suppport.
191 return;
192 }
193 183
194 std::string request(kSOCKS5IPv6Request, 184 std::string request(kSOCKS5IPv6Request,
195 arraysize(kSOCKS5IPv6Request)); 185 arraysize(kSOCKS5IPv6Request));
196 request.append(reinterpret_cast<const char*>(&ipv6_addr), sizeof(ipv6_addr)); 186 request.append(reinterpret_cast<const char*>(&ipv6_addr), sizeof(ipv6_addr));
197 request.append(reinterpret_cast<const char*>(&kNwPort), sizeof(kNwPort)); 187 request.append(reinterpret_cast<const char*>(&kNwPort), sizeof(kNwPort));
198 188
199 MockWrite data_writes[] = { 189 MockWrite data_writes[] = {
200 MockWrite(false, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), 190 MockWrite(false, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
201 MockWrite(false, request.data(), request.size()) }; 191 MockWrite(false, request.data(), request.size()) };
202 MockRead data_reads[] = { 192 MockRead data_reads[] = {
203 MockRead(false, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), 193 MockRead(false, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
204 MockRead(false, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) }; 194 MockRead(false, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) };
205 195
206 user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); 196 user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
207 197
208 rv = user_sock_->Connect(&callback_); 198 int rv = user_sock_->Connect(&callback_);
209 EXPECT_EQ(ERR_IO_PENDING, rv); 199 EXPECT_EQ(ERR_IO_PENDING, rv);
210 rv = callback_.WaitForResult(); 200 rv = callback_.WaitForResult();
211 EXPECT_EQ(OK, rv); 201 EXPECT_EQ(OK, rv);
212 EXPECT_TRUE(user_sock_->IsConnected()); 202 EXPECT_TRUE(user_sock_->IsConnected());
213 EXPECT_EQ(SOCKS5ClientSocket::kEndPointResolvedIPv6, 203 EXPECT_EQ(SOCKS5ClientSocket::kEndPointResolvedIPv6,
214 user_sock_->address_type_); 204 user_sock_->address_type_);
215 } 205 }
216 206
217 TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) { 207 TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) {
218 const std::string hostname = "www.google.com"; 208 const std::string hostname = "www.google.com";
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 int rv = user_sock_->Connect(&callback_); 279 int rv = user_sock_->Connect(&callback_);
290 EXPECT_EQ(ERR_IO_PENDING, rv); 280 EXPECT_EQ(ERR_IO_PENDING, rv);
291 rv = callback_.WaitForResult(); 281 rv = callback_.WaitForResult();
292 EXPECT_EQ(OK, rv); 282 EXPECT_EQ(OK, rv);
293 EXPECT_TRUE(user_sock_->IsConnected()); 283 EXPECT_TRUE(user_sock_->IsConnected());
294 } 284 }
295 } 285 }
296 286
297 } // namespace net 287 } // namespace net
298 288
OLDNEW
« no previous file with comments | « net/base/mock_host_resolver.cc ('k') | net/socket/socks_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698