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/dns/address_sorter_posix.h" | 5 #include "net/dns/address_sorter_posix.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 // A mock socket which binds to source address according to AddressMapping. | 30 // A mock socket which binds to source address according to AddressMapping. |
31 class TestUDPClientSocket : public DatagramClientSocket { | 31 class TestUDPClientSocket : public DatagramClientSocket { |
32 public: | 32 public: |
33 explicit TestUDPClientSocket(const AddressMapping* mapping) | 33 explicit TestUDPClientSocket(const AddressMapping* mapping) |
34 : mapping_(mapping), connected_(false) {} | 34 : mapping_(mapping), connected_(false) {} |
35 | 35 |
36 virtual ~TestUDPClientSocket() {} | 36 virtual ~TestUDPClientSocket() {} |
37 | 37 |
38 virtual int Read(IOBuffer*, int, const CompletionCallback&) OVERRIDE { | 38 virtual int Read(IOBuffer*, int, const CompletionCallback&) override { |
39 NOTIMPLEMENTED(); | 39 NOTIMPLEMENTED(); |
40 return OK; | 40 return OK; |
41 } | 41 } |
42 virtual int Write(IOBuffer*, int, const CompletionCallback&) OVERRIDE { | 42 virtual int Write(IOBuffer*, int, const CompletionCallback&) override { |
43 NOTIMPLEMENTED(); | 43 NOTIMPLEMENTED(); |
44 return OK; | 44 return OK; |
45 } | 45 } |
46 virtual int SetReceiveBufferSize(int32) OVERRIDE { | 46 virtual int SetReceiveBufferSize(int32) override { |
47 return OK; | 47 return OK; |
48 } | 48 } |
49 virtual int SetSendBufferSize(int32) OVERRIDE { | 49 virtual int SetSendBufferSize(int32) override { |
50 return OK; | 50 return OK; |
51 } | 51 } |
52 | 52 |
53 virtual void Close() OVERRIDE {} | 53 virtual void Close() override {} |
54 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | 54 virtual int GetPeerAddress(IPEndPoint* address) const override { |
55 NOTIMPLEMENTED(); | 55 NOTIMPLEMENTED(); |
56 return OK; | 56 return OK; |
57 } | 57 } |
58 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | 58 virtual int GetLocalAddress(IPEndPoint* address) const override { |
59 if (!connected_) | 59 if (!connected_) |
60 return ERR_UNEXPECTED; | 60 return ERR_UNEXPECTED; |
61 *address = local_endpoint_; | 61 *address = local_endpoint_; |
62 return OK; | 62 return OK; |
63 } | 63 } |
64 | 64 |
65 virtual int Connect(const IPEndPoint& remote) OVERRIDE { | 65 virtual int Connect(const IPEndPoint& remote) override { |
66 if (connected_) | 66 if (connected_) |
67 return ERR_UNEXPECTED; | 67 return ERR_UNEXPECTED; |
68 AddressMapping::const_iterator it = mapping_->find(remote.address()); | 68 AddressMapping::const_iterator it = mapping_->find(remote.address()); |
69 if (it == mapping_->end()) | 69 if (it == mapping_->end()) |
70 return ERR_FAILED; | 70 return ERR_FAILED; |
71 connected_ = true; | 71 connected_ = true; |
72 local_endpoint_ = IPEndPoint(it->second, 39874 /* arbitrary port */); | 72 local_endpoint_ = IPEndPoint(it->second, 39874 /* arbitrary port */); |
73 return OK; | 73 return OK; |
74 } | 74 } |
75 | 75 |
76 virtual const BoundNetLog& NetLog() const OVERRIDE { | 76 virtual const BoundNetLog& NetLog() const override { |
77 return net_log_; | 77 return net_log_; |
78 } | 78 } |
79 | 79 |
80 private: | 80 private: |
81 BoundNetLog net_log_; | 81 BoundNetLog net_log_; |
82 const AddressMapping* mapping_; | 82 const AddressMapping* mapping_; |
83 bool connected_; | 83 bool connected_; |
84 IPEndPoint local_endpoint_; | 84 IPEndPoint local_endpoint_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(TestUDPClientSocket); | 86 DISALLOW_COPY_AND_ASSIGN(TestUDPClientSocket); |
87 }; | 87 }; |
88 | 88 |
89 // Creates TestUDPClientSockets and maintains an AddressMapping. | 89 // Creates TestUDPClientSockets and maintains an AddressMapping. |
90 class TestSocketFactory : public ClientSocketFactory { | 90 class TestSocketFactory : public ClientSocketFactory { |
91 public: | 91 public: |
92 TestSocketFactory() {} | 92 TestSocketFactory() {} |
93 virtual ~TestSocketFactory() {} | 93 virtual ~TestSocketFactory() {} |
94 | 94 |
95 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 95 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
96 DatagramSocket::BindType, | 96 DatagramSocket::BindType, |
97 const RandIntCallback&, | 97 const RandIntCallback&, |
98 NetLog*, | 98 NetLog*, |
99 const NetLog::Source&) OVERRIDE { | 99 const NetLog::Source&) override { |
100 return scoped_ptr<DatagramClientSocket>(new TestUDPClientSocket(&mapping_)); | 100 return scoped_ptr<DatagramClientSocket>(new TestUDPClientSocket(&mapping_)); |
101 } | 101 } |
102 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | 102 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( |
103 const AddressList&, | 103 const AddressList&, |
104 NetLog*, | 104 NetLog*, |
105 const NetLog::Source&) OVERRIDE { | 105 const NetLog::Source&) override { |
106 NOTIMPLEMENTED(); | 106 NOTIMPLEMENTED(); |
107 return scoped_ptr<StreamSocket>(); | 107 return scoped_ptr<StreamSocket>(); |
108 } | 108 } |
109 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 109 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
110 scoped_ptr<ClientSocketHandle>, | 110 scoped_ptr<ClientSocketHandle>, |
111 const HostPortPair&, | 111 const HostPortPair&, |
112 const SSLConfig&, | 112 const SSLConfig&, |
113 const SSLClientSocketContext&) OVERRIDE { | 113 const SSLClientSocketContext&) override { |
114 NOTIMPLEMENTED(); | 114 NOTIMPLEMENTED(); |
115 return scoped_ptr<SSLClientSocket>(); | 115 return scoped_ptr<SSLClientSocket>(); |
116 } | 116 } |
117 virtual void ClearSSLSessionCache() OVERRIDE { | 117 virtual void ClearSSLSessionCache() override { |
118 NOTIMPLEMENTED(); | 118 NOTIMPLEMENTED(); |
119 } | 119 } |
120 | 120 |
121 void AddMapping(const IPAddressNumber& dst, const IPAddressNumber& src) { | 121 void AddMapping(const IPAddressNumber& dst, const IPAddressNumber& src) { |
122 mapping_[dst] = src; | 122 mapping_[dst] = src; |
123 } | 123 } |
124 | 124 |
125 private: | 125 private: |
126 AddressMapping mapping_; | 126 AddressMapping mapping_; |
127 | 127 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 AddMapping("4000::1", "4000::10"); // global unicast | 318 AddMapping("4000::1", "4000::10"); // global unicast |
319 AddMapping("ff32::2", "fe81::20"); // deprecated link-local multicast | 319 AddMapping("ff32::2", "fe81::20"); // deprecated link-local multicast |
320 GetSourceInfo("fe81::20")->deprecated = true; | 320 GetSourceInfo("fe81::20")->deprecated = true; |
321 const char* addresses[] = { "ff3e::1", "ff32::2", "4000::1", "ff32::1", "::1", | 321 const char* addresses[] = { "ff3e::1", "ff32::2", "4000::1", "ff32::1", "::1", |
322 "8.0.0.1", NULL }; | 322 "8.0.0.1", NULL }; |
323 const int order[] = { 4, 3, 0, 2, 1, -1 }; | 323 const int order[] = { 4, 3, 0, 2, 1, -1 }; |
324 Verify(addresses, order); | 324 Verify(addresses, order); |
325 } | 325 } |
326 | 326 |
327 } // namespace net | 327 } // namespace net |
OLD | NEW |