Fix scrollbar painting problems in pdf files in HiDPI mode with fractional scales.
[chromium-blink-merge.git] / net / socket / socket_test_util.h
blob8f046266404710d96f7bfb62a516a53df836d75d
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
3 // found in the LICENSE file.
5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_
8 #include <cstring>
9 #include <deque>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/logging.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/scoped_vector.h"
19 #include "base/memory/weak_ptr.h"
20 #include "base/strings/string16.h"
21 #include "net/base/address_list.h"
22 #include "net/base/io_buffer.h"
23 #include "net/base/net_errors.h"
24 #include "net/base/net_log.h"
25 #include "net/base/test_completion_callback.h"
26 #include "net/http/http_auth_controller.h"
27 #include "net/http/http_proxy_client_socket_pool.h"
28 #include "net/socket/client_socket_factory.h"
29 #include "net/socket/client_socket_handle.h"
30 #include "net/socket/socks_client_socket_pool.h"
31 #include "net/socket/ssl_client_socket.h"
32 #include "net/socket/ssl_client_socket_pool.h"
33 #include "net/socket/transport_client_socket_pool.h"
34 #include "net/ssl/ssl_config_service.h"
35 #include "net/udp/datagram_client_socket.h"
36 #include "testing/gtest/include/gtest/gtest.h"
38 namespace net {
40 enum {
41 // A private network error code used by the socket test utility classes.
42 // If the |result| member of a MockRead is
43 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a
44 // marker that indicates the peer will close the connection after the next
45 // MockRead. The other members of that MockRead are ignored.
46 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000,
49 class AsyncSocket;
50 class ChannelIDService;
51 class MockClientSocket;
52 class SSLClientSocket;
53 class StreamSocket;
55 enum IoMode {
56 ASYNC,
57 SYNCHRONOUS
60 struct MockConnect {
61 // Asynchronous connection success.
62 // Creates a MockConnect with |mode| ASYC, |result| OK, and
63 // |peer_addr| 192.0.2.33.
64 MockConnect();
65 // Creates a MockConnect with the specified mode and result, with
66 // |peer_addr| 192.0.2.33.
67 MockConnect(IoMode io_mode, int r);
68 MockConnect(IoMode io_mode, int r, IPEndPoint addr);
69 ~MockConnect();
71 IoMode mode;
72 int result;
73 IPEndPoint peer_addr;
76 // MockRead and MockWrite shares the same interface and members, but we'd like
77 // to have distinct types because we don't want to have them used
78 // interchangably. To do this, a struct template is defined, and MockRead and
79 // MockWrite are instantiated by using this template. Template parameter |type|
80 // is not used in the struct definition (it purely exists for creating a new
81 // type).
83 // |data| in MockRead and MockWrite has different meanings: |data| in MockRead
84 // is the data returned from the socket when MockTCPClientSocket::Read() is
85 // attempted, while |data| in MockWrite is the expected data that should be
86 // given in MockTCPClientSocket::Write().
87 enum MockReadWriteType {
88 MOCK_READ,
89 MOCK_WRITE
92 template <MockReadWriteType type>
93 struct MockReadWrite {
94 // Flag to indicate that the message loop should be terminated.
95 enum {
96 STOPLOOP = 1 << 31
99 // Default
100 MockReadWrite()
101 : mode(SYNCHRONOUS),
102 result(0),
103 data(NULL),
104 data_len(0),
105 sequence_number(0),
106 time_stamp(base::Time::Now()) {}
108 // Read/write failure (no data).
109 MockReadWrite(IoMode io_mode, int result)
110 : mode(io_mode),
111 result(result),
112 data(NULL),
113 data_len(0),
114 sequence_number(0),
115 time_stamp(base::Time::Now()) {}
117 // Read/write failure (no data), with sequence information.
118 MockReadWrite(IoMode io_mode, int result, int seq)
119 : mode(io_mode),
120 result(result),
121 data(NULL),
122 data_len(0),
123 sequence_number(seq),
124 time_stamp(base::Time::Now()) {}
126 // Asynchronous read/write success (inferred data length).
127 explicit MockReadWrite(const char* data)
128 : mode(ASYNC),
129 result(0),
130 data(data),
131 data_len(strlen(data)),
132 sequence_number(0),
133 time_stamp(base::Time::Now()) {}
135 // Read/write success (inferred data length).
136 MockReadWrite(IoMode io_mode, const char* data)
137 : mode(io_mode),
138 result(0),
139 data(data),
140 data_len(strlen(data)),
141 sequence_number(0),
142 time_stamp(base::Time::Now()) {}
144 // Read/write success.
145 MockReadWrite(IoMode io_mode, const char* data, int data_len)
146 : mode(io_mode),
147 result(0),
148 data(data),
149 data_len(data_len),
150 sequence_number(0),
151 time_stamp(base::Time::Now()) {}
153 // Read/write success (inferred data length) with sequence information.
154 MockReadWrite(IoMode io_mode, int seq, const char* data)
155 : mode(io_mode),
156 result(0),
157 data(data),
158 data_len(strlen(data)),
159 sequence_number(seq),
160 time_stamp(base::Time::Now()) {}
162 // Read/write success with sequence information.
163 MockReadWrite(IoMode io_mode, const char* data, int data_len, int seq)
164 : mode(io_mode),
165 result(0),
166 data(data),
167 data_len(data_len),
168 sequence_number(seq),
169 time_stamp(base::Time::Now()) {}
171 IoMode mode;
172 int result;
173 const char* data;
174 int data_len;
176 // For OrderedSocketData, which only allows reads to occur in a particular
177 // sequence. If a read occurs before the given |sequence_number| is reached,
178 // an ERR_IO_PENDING is returned.
179 int sequence_number; // The sequence number at which a read is allowed
180 // to occur.
181 base::Time time_stamp; // The time stamp at which the operation occurred.
184 typedef MockReadWrite<MOCK_READ> MockRead;
185 typedef MockReadWrite<MOCK_WRITE> MockWrite;
187 struct MockWriteResult {
188 MockWriteResult(IoMode io_mode, int result) : mode(io_mode), result(result) {}
190 IoMode mode;
191 int result;
194 // The SocketDataProvider is an interface used by the MockClientSocket
195 // for getting data about individual reads and writes on the socket.
196 class SocketDataProvider {
197 public:
198 SocketDataProvider() : socket_(NULL) {}
200 virtual ~SocketDataProvider() {}
202 // Returns the buffer and result code for the next simulated read.
203 // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller
204 // that it will be called via the AsyncSocket::OnReadComplete()
205 // function at a later time.
206 virtual MockRead GetNextRead() = 0;
207 virtual MockWriteResult OnWrite(const std::string& data) = 0;
208 virtual void Reset() = 0;
210 // Accessor for the socket which is using the SocketDataProvider.
211 AsyncSocket* socket() { return socket_; }
212 void set_socket(AsyncSocket* socket) { socket_ = socket; }
214 MockConnect connect_data() const { return connect_; }
215 void set_connect_data(const MockConnect& connect) { connect_ = connect; }
217 private:
218 MockConnect connect_;
219 AsyncSocket* socket_;
221 DISALLOW_COPY_AND_ASSIGN(SocketDataProvider);
224 // The AsyncSocket is an interface used by the SocketDataProvider to
225 // complete the asynchronous read operation.
226 class AsyncSocket {
227 public:
228 // If an async IO is pending because the SocketDataProvider returned
229 // ERR_IO_PENDING, then the AsyncSocket waits until this OnReadComplete
230 // is called to complete the asynchronous read operation.
231 // data.async is ignored, and this read is completed synchronously as
232 // part of this call.
233 virtual void OnReadComplete(const MockRead& data) = 0;
234 virtual void OnConnectComplete(const MockConnect& data) = 0;
237 // SocketDataProvider which responds based on static tables of mock reads and
238 // writes.
239 class StaticSocketDataProvider : public SocketDataProvider {
240 public:
241 StaticSocketDataProvider();
242 StaticSocketDataProvider(MockRead* reads,
243 size_t reads_count,
244 MockWrite* writes,
245 size_t writes_count);
246 virtual ~StaticSocketDataProvider();
248 // These functions get access to the next available read and write data.
249 const MockRead& PeekRead() const;
250 const MockWrite& PeekWrite() const;
251 // These functions get random access to the read and write data, for timing.
252 const MockRead& PeekRead(size_t index) const;
253 const MockWrite& PeekWrite(size_t index) const;
254 size_t read_index() const { return read_index_; }
255 size_t write_index() const { return write_index_; }
256 size_t read_count() const { return read_count_; }
257 size_t write_count() const { return write_count_; }
259 bool at_read_eof() const { return read_index_ >= read_count_; }
260 bool at_write_eof() const { return write_index_ >= write_count_; }
262 virtual void CompleteRead() {}
264 // SocketDataProvider implementation.
265 virtual MockRead GetNextRead() OVERRIDE;
266 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
267 virtual void Reset() OVERRIDE;
269 private:
270 MockRead* reads_;
271 size_t read_index_;
272 size_t read_count_;
273 MockWrite* writes_;
274 size_t write_index_;
275 size_t write_count_;
277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
280 // SocketDataProvider which can make decisions about next mock reads based on
281 // received writes. It can also be used to enforce order of operations, for
282 // example that tested code must send the "Hello!" message before receiving
283 // response. This is useful for testing conversation-like protocols like FTP.
284 class DynamicSocketDataProvider : public SocketDataProvider {
285 public:
286 DynamicSocketDataProvider();
287 virtual ~DynamicSocketDataProvider();
289 int short_read_limit() const { return short_read_limit_; }
290 void set_short_read_limit(int limit) { short_read_limit_ = limit; }
292 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; }
294 // SocketDataProvider implementation.
295 virtual MockRead GetNextRead() OVERRIDE;
296 virtual MockWriteResult OnWrite(const std::string& data) = 0;
297 virtual void Reset() OVERRIDE;
299 protected:
300 // The next time there is a read from this socket, it will return |data|.
301 // Before calling SimulateRead next time, the previous data must be consumed.
302 void SimulateRead(const char* data, size_t length);
303 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); }
305 private:
306 std::deque<MockRead> reads_;
308 // Max number of bytes we will read at a time. 0 means no limit.
309 int short_read_limit_;
311 // If true, we'll not require the client to consume all data before we
312 // mock the next read.
313 bool allow_unconsumed_reads_;
315 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider);
318 // SSLSocketDataProviders only need to keep track of the return code from calls
319 // to Connect().
320 struct SSLSocketDataProvider {
321 SSLSocketDataProvider(IoMode mode, int result);
322 ~SSLSocketDataProvider();
324 void SetNextProto(NextProto proto);
326 MockConnect connect;
327 SSLClientSocket::NextProtoStatus next_proto_status;
328 std::string next_proto;
329 bool was_npn_negotiated;
330 NextProto protocol_negotiated;
331 bool client_cert_sent;
332 SSLCertRequestInfo* cert_request_info;
333 scoped_refptr<X509Certificate> cert;
334 bool channel_id_sent;
335 ChannelIDService* channel_id_service;
336 int connection_status;
337 // Indicates that the socket should block in the Connect method.
338 bool should_block_on_connect;
339 // Whether or not the Socket should behave like there is a pre-existing
340 // session to resume. Whether or not such a session is reported as
341 // resumed is controlled by |connection_status|.
342 bool is_in_session_cache;
345 // A DataProvider where the client must write a request before the reads (e.g.
346 // the response) will complete.
347 class DelayedSocketData : public StaticSocketDataProvider {
348 public:
349 // |write_delay| the number of MockWrites to complete before allowing
350 // a MockRead to complete.
351 // |reads| the list of MockRead completions.
352 // |writes| the list of MockWrite completions.
353 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
354 // MockRead(true, 0, 0);
355 DelayedSocketData(int write_delay,
356 MockRead* reads,
357 size_t reads_count,
358 MockWrite* writes,
359 size_t writes_count);
361 // |connect| the result for the connect phase.
362 // |reads| the list of MockRead completions.
363 // |write_delay| the number of MockWrites to complete before allowing
364 // a MockRead to complete.
365 // |writes| the list of MockWrite completions.
366 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
367 // MockRead(true, 0, 0);
368 DelayedSocketData(const MockConnect& connect,
369 int write_delay,
370 MockRead* reads,
371 size_t reads_count,
372 MockWrite* writes,
373 size_t writes_count);
374 virtual ~DelayedSocketData();
376 void ForceNextRead();
378 // StaticSocketDataProvider:
379 virtual MockRead GetNextRead() OVERRIDE;
380 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
381 virtual void Reset() OVERRIDE;
382 virtual void CompleteRead() OVERRIDE;
384 private:
385 int write_delay_;
386 bool read_in_progress_;
388 base::WeakPtrFactory<DelayedSocketData> weak_factory_;
390 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData);
393 // A DataProvider where the reads are ordered.
394 // If a read is requested before its sequence number is reached, we return an
395 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to
396 // wait).
397 // The sequence number is incremented on every read and write operation.
398 // The message loop may be interrupted by setting the high bit of the sequence
399 // number in the MockRead's sequence number. When that MockRead is reached,
400 // we post a Quit message to the loop. This allows us to interrupt the reading
401 // of data before a complete message has arrived, and provides support for
402 // testing server push when the request is issued while the response is in the
403 // middle of being received.
404 class OrderedSocketData : public StaticSocketDataProvider {
405 public:
406 // |reads| the list of MockRead completions.
407 // |writes| the list of MockWrite completions.
408 // Note: All MockReads and MockWrites must be async.
409 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
410 // MockRead(true, 0, 0);
411 OrderedSocketData(MockRead* reads,
412 size_t reads_count,
413 MockWrite* writes,
414 size_t writes_count);
415 virtual ~OrderedSocketData();
417 // |connect| the result for the connect phase.
418 // |reads| the list of MockRead completions.
419 // |writes| the list of MockWrite completions.
420 // Note: All MockReads and MockWrites must be async.
421 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
422 // MockRead(true, 0, 0);
423 OrderedSocketData(const MockConnect& connect,
424 MockRead* reads,
425 size_t reads_count,
426 MockWrite* writes,
427 size_t writes_count);
429 // Posts a quit message to the current message loop, if one is running.
430 void EndLoop();
432 // StaticSocketDataProvider:
433 virtual MockRead GetNextRead() OVERRIDE;
434 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
435 virtual void Reset() OVERRIDE;
436 virtual void CompleteRead() OVERRIDE;
438 private:
439 int sequence_number_;
440 int loop_stop_stage_;
441 bool blocked_;
443 base::WeakPtrFactory<OrderedSocketData> weak_factory_;
445 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData);
448 class DeterministicMockTCPClientSocket;
450 // This class gives the user full control over the network activity,
451 // specifically the timing of the COMPLETION of I/O operations. Regardless of
452 // the order in which I/O operations are initiated, this class ensures that they
453 // complete in the correct order.
455 // Network activity is modeled as a sequence of numbered steps which is
456 // incremented whenever an I/O operation completes. This can happen under two
457 // different circumstances:
459 // 1) Performing a synchronous I/O operation. (Invoking Read() or Write()
460 // when the corresponding MockRead or MockWrite is marked !async).
461 // 2) Running the Run() method of this class. The run method will invoke
462 // the current MessageLoop, running all pending events, and will then
463 // invoke any pending IO callbacks.
465 // In addition, this class allows for I/O processing to "stop" at a specified
466 // step, by calling SetStop(int) or StopAfter(int). Initiating an I/O operation
467 // by calling Read() or Write() while stopped is permitted if the operation is
468 // asynchronous. It is an error to perform synchronous I/O while stopped.
470 // When creating the MockReads and MockWrites, note that the sequence number
471 // refers to the number of the step in which the I/O will complete. In the
472 // case of synchronous I/O, this will be the same step as the I/O is initiated.
473 // However, in the case of asynchronous I/O, this I/O may be initiated in
474 // a much earlier step. Furthermore, when the a Read() or Write() is separated
475 // from its completion by other Read() or Writes()'s, it can not be marked
476 // synchronous. If it is, ERR_UNUEXPECTED will be returned indicating that a
477 // synchronous Read() or Write() could not be completed synchronously because of
478 // the specific ordering constraints.
480 // Sequence numbers are preserved across both reads and writes. There should be
481 // no gaps in sequence numbers, and no repeated sequence numbers. i.e.
482 // MockRead reads[] = {
483 // MockRead(false, "first read", length, 0) // sync
484 // MockRead(true, "second read", length, 2) // async
485 // };
486 // MockWrite writes[] = {
487 // MockWrite(true, "first write", length, 1), // async
488 // MockWrite(false, "second write", length, 3), // sync
489 // };
491 // Example control flow:
492 // Read() is called. The current step is 0. The first available read is
493 // synchronous, so the call to Read() returns length. The current step is
494 // now 1. Next, Read() is called again. The next available read can
495 // not be completed until step 2, so Read() returns ERR_IO_PENDING. The current
496 // step is still 1. Write is called(). The first available write is able to
497 // complete in this step, but is marked asynchronous. Write() returns
498 // ERR_IO_PENDING. The current step is still 1. At this point RunFor(1) is
499 // called which will cause the write callback to be invoked, and will then
500 // stop. The current state is now 2. RunFor(1) is called again, which
501 // causes the read callback to be invoked, and will then stop. Then current
502 // step is 2. Write() is called again. Then next available write is
503 // synchronous so the call to Write() returns length.
505 // For examples of how to use this class, see:
506 // deterministic_socket_data_unittests.cc
507 class DeterministicSocketData : public StaticSocketDataProvider {
508 public:
509 // The Delegate is an abstract interface which handles the communication from
510 // the DeterministicSocketData to the Deterministic MockSocket. The
511 // MockSockets directly store a pointer to the DeterministicSocketData,
512 // whereas the DeterministicSocketData only stores a pointer to the
513 // abstract Delegate interface.
514 class Delegate {
515 public:
516 // Returns true if there is currently a write pending. That is to say, if
517 // an asynchronous write has been started but the callback has not been
518 // invoked.
519 virtual bool WritePending() const = 0;
520 // Returns true if there is currently a read pending. That is to say, if
521 // an asynchronous read has been started but the callback has not been
522 // invoked.
523 virtual bool ReadPending() const = 0;
524 // Called to complete an asynchronous write to execute the write callback.
525 virtual void CompleteWrite() = 0;
526 // Called to complete an asynchronous read to execute the read callback.
527 virtual int CompleteRead() = 0;
529 protected:
530 virtual ~Delegate() {}
533 // |reads| the list of MockRead completions.
534 // |writes| the list of MockWrite completions.
535 DeterministicSocketData(MockRead* reads,
536 size_t reads_count,
537 MockWrite* writes,
538 size_t writes_count);
539 virtual ~DeterministicSocketData();
541 // Consume all the data up to the give stop point (via SetStop()).
542 void Run();
544 // Set the stop point to be |steps| from now, and then invoke Run().
545 void RunFor(int steps);
547 // Stop at step |seq|, which must be in the future.
548 virtual void SetStop(int seq);
550 // Stop |seq| steps after the current step.
551 virtual void StopAfter(int seq);
552 bool stopped() const { return stopped_; }
553 void SetStopped(bool val) { stopped_ = val; }
554 MockRead& current_read() { return current_read_; }
555 MockWrite& current_write() { return current_write_; }
556 int sequence_number() const { return sequence_number_; }
557 void set_delegate(base::WeakPtr<Delegate> delegate) { delegate_ = delegate; }
559 // StaticSocketDataProvider:
561 // When the socket calls Read(), that calls GetNextRead(), and expects either
562 // ERR_IO_PENDING or data.
563 virtual MockRead GetNextRead() OVERRIDE;
565 // When the socket calls Write(), it always completes synchronously. OnWrite()
566 // checks to make sure the written data matches the expected data. The
567 // callback will not be invoked until its sequence number is reached.
568 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
569 virtual void Reset() OVERRIDE;
570 virtual void CompleteRead() OVERRIDE {}
572 private:
573 // Invoke the read and write callbacks, if the timing is appropriate.
574 void InvokeCallbacks();
576 void NextStep();
578 void VerifyCorrectSequenceNumbers(MockRead* reads,
579 size_t reads_count,
580 MockWrite* writes,
581 size_t writes_count);
583 int sequence_number_;
584 MockRead current_read_;
585 MockWrite current_write_;
586 int stopping_sequence_number_;
587 bool stopped_;
588 base::WeakPtr<Delegate> delegate_;
589 bool print_debug_;
590 bool is_running_;
593 // Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}StreamSocket
594 // objects get instantiated, they take their data from the i'th element of this
595 // array.
596 template <typename T>
597 class SocketDataProviderArray {
598 public:
599 SocketDataProviderArray() : next_index_(0) {}
601 T* GetNext() {
602 DCHECK_LT(next_index_, data_providers_.size());
603 return data_providers_[next_index_++];
606 void Add(T* data_provider) {
607 DCHECK(data_provider);
608 data_providers_.push_back(data_provider);
611 size_t next_index() { return next_index_; }
613 void ResetNextIndex() { next_index_ = 0; }
615 private:
616 // Index of the next |data_providers_| element to use. Not an iterator
617 // because those are invalidated on vector reallocation.
618 size_t next_index_;
620 // SocketDataProviders to be returned.
621 std::vector<T*> data_providers_;
624 class MockUDPClientSocket;
625 class MockTCPClientSocket;
626 class MockSSLClientSocket;
628 // ClientSocketFactory which contains arrays of sockets of each type.
629 // You should first fill the arrays using AddMock{SSL,}Socket. When the factory
630 // is asked to create a socket, it takes next entry from appropriate array.
631 // You can use ResetNextMockIndexes to reset that next entry index for all mock
632 // socket types.
633 class MockClientSocketFactory : public ClientSocketFactory {
634 public:
635 MockClientSocketFactory();
636 virtual ~MockClientSocketFactory();
638 void AddSocketDataProvider(SocketDataProvider* socket);
639 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
640 void ResetNextMockIndexes();
642 SocketDataProviderArray<SocketDataProvider>& mock_data() {
643 return mock_data_;
646 // Note: this method is unsafe; the elements of the returned vector
647 // are not necessarily valid.
648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const {
649 return ssl_client_sockets_;
652 // ClientSocketFactory
653 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
654 DatagramSocket::BindType bind_type,
655 const RandIntCallback& rand_int_cb,
656 NetLog* net_log,
657 const NetLog::Source& source) OVERRIDE;
658 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
659 const AddressList& addresses,
660 NetLog* net_log,
661 const NetLog::Source& source) OVERRIDE;
662 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
663 scoped_ptr<ClientSocketHandle> transport_socket,
664 const HostPortPair& host_and_port,
665 const SSLConfig& ssl_config,
666 const SSLClientSocketContext& context) OVERRIDE;
667 virtual void ClearSSLSessionCache() OVERRIDE;
669 private:
670 SocketDataProviderArray<SocketDataProvider> mock_data_;
671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
672 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
675 class MockClientSocket : public SSLClientSocket {
676 public:
677 // Value returned by GetTLSUniqueChannelBinding().
678 static const char kTlsUnique[];
680 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
681 // unique socket IDs.
682 explicit MockClientSocket(const BoundNetLog& net_log);
684 // Socket implementation.
685 virtual int Read(IOBuffer* buf,
686 int buf_len,
687 const CompletionCallback& callback) = 0;
688 virtual int Write(IOBuffer* buf,
689 int buf_len,
690 const CompletionCallback& callback) = 0;
691 virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
692 virtual int SetSendBufferSize(int32 size) OVERRIDE;
694 // StreamSocket implementation.
695 virtual int Connect(const CompletionCallback& callback) = 0;
696 virtual void Disconnect() OVERRIDE;
697 virtual bool IsConnected() const OVERRIDE;
698 virtual bool IsConnectedAndIdle() const OVERRIDE;
699 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
700 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
701 virtual const BoundNetLog& NetLog() const OVERRIDE;
702 virtual void SetSubresourceSpeculation() OVERRIDE {}
703 virtual void SetOmniboxSpeculation() OVERRIDE {}
705 // SSLClientSocket implementation.
706 virtual bool InSessionCache() const OVERRIDE;
707 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE;
708 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
709 OVERRIDE;
710 virtual int ExportKeyingMaterial(const base::StringPiece& label,
711 bool has_context,
712 const base::StringPiece& context,
713 unsigned char* out,
714 unsigned int outlen) OVERRIDE;
715 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE;
716 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE;
717 virtual ChannelIDService* GetChannelIDService() const OVERRIDE;
719 protected:
720 virtual ~MockClientSocket();
721 void RunCallbackAsync(const CompletionCallback& callback, int result);
722 void RunCallback(const CompletionCallback& callback, int result);
724 // SSLClientSocket implementation.
725 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
726 const OVERRIDE;
728 // True if Connect completed successfully and Disconnect hasn't been called.
729 bool connected_;
731 // Address of the "remote" peer we're connected to.
732 IPEndPoint peer_addr_;
734 BoundNetLog net_log_;
736 private:
737 base::WeakPtrFactory<MockClientSocket> weak_factory_;
739 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
742 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
743 public:
744 MockTCPClientSocket(const AddressList& addresses,
745 net::NetLog* net_log,
746 SocketDataProvider* socket);
747 virtual ~MockTCPClientSocket();
749 const AddressList& addresses() const { return addresses_; }
751 // Socket implementation.
752 virtual int Read(IOBuffer* buf,
753 int buf_len,
754 const CompletionCallback& callback) OVERRIDE;
755 virtual int Write(IOBuffer* buf,
756 int buf_len,
757 const CompletionCallback& callback) OVERRIDE;
759 // StreamSocket implementation.
760 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
761 virtual void Disconnect() OVERRIDE;
762 virtual bool IsConnected() const OVERRIDE;
763 virtual bool IsConnectedAndIdle() const OVERRIDE;
764 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
765 virtual bool WasEverUsed() const OVERRIDE;
766 virtual bool UsingTCPFastOpen() const OVERRIDE;
767 virtual bool WasNpnNegotiated() const OVERRIDE;
768 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
770 // AsyncSocket:
771 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
772 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
774 private:
775 int CompleteRead();
777 AddressList addresses_;
779 SocketDataProvider* data_;
780 int read_offset_;
781 MockRead read_data_;
782 bool need_read_data_;
784 // True if the peer has closed the connection. This allows us to simulate
785 // the recv(..., MSG_PEEK) call in the IsConnectedAndIdle method of the real
786 // TCPClientSocket.
787 bool peer_closed_connection_;
789 // While an asynchronous IO is pending, we save our user-buffer state.
790 scoped_refptr<IOBuffer> pending_buf_;
791 int pending_buf_len_;
792 CompletionCallback pending_callback_;
793 bool was_used_to_convey_data_;
795 DISALLOW_COPY_AND_ASSIGN(MockTCPClientSocket);
798 // DeterministicSocketHelper is a helper class that can be used
799 // to simulate net::Socket::Read() and net::Socket::Write()
800 // using deterministic |data|.
801 // Note: This is provided as a common helper class because
802 // of the inheritance hierarchy of DeterministicMock[UDP,TCP]ClientSocket and a
803 // desire not to introduce an additional common base class.
804 class DeterministicSocketHelper {
805 public:
806 DeterministicSocketHelper(net::NetLog* net_log,
807 DeterministicSocketData* data);
808 virtual ~DeterministicSocketHelper();
810 bool write_pending() const { return write_pending_; }
811 bool read_pending() const { return read_pending_; }
813 void CompleteWrite();
814 int CompleteRead();
816 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
817 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
819 const BoundNetLog& net_log() const { return net_log_; }
821 bool was_used_to_convey_data() const { return was_used_to_convey_data_; }
823 bool peer_closed_connection() const { return peer_closed_connection_; }
825 DeterministicSocketData* data() const { return data_; }
827 private:
828 bool write_pending_;
829 CompletionCallback write_callback_;
830 int write_result_;
832 MockRead read_data_;
834 IOBuffer* read_buf_;
835 int read_buf_len_;
836 bool read_pending_;
837 CompletionCallback read_callback_;
838 DeterministicSocketData* data_;
839 bool was_used_to_convey_data_;
840 bool peer_closed_connection_;
841 BoundNetLog net_log_;
844 // Mock UDP socket to be used in conjunction with DeterministicSocketData.
845 class DeterministicMockUDPClientSocket
846 : public DatagramClientSocket,
847 public AsyncSocket,
848 public DeterministicSocketData::Delegate,
849 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> {
850 public:
851 DeterministicMockUDPClientSocket(net::NetLog* net_log,
852 DeterministicSocketData* data);
853 virtual ~DeterministicMockUDPClientSocket();
855 // DeterministicSocketData::Delegate:
856 virtual bool WritePending() const OVERRIDE;
857 virtual bool ReadPending() const OVERRIDE;
858 virtual void CompleteWrite() OVERRIDE;
859 virtual int CompleteRead() OVERRIDE;
861 // Socket implementation.
862 virtual int Read(IOBuffer* buf,
863 int buf_len,
864 const CompletionCallback& callback) OVERRIDE;
865 virtual int Write(IOBuffer* buf,
866 int buf_len,
867 const CompletionCallback& callback) OVERRIDE;
868 virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
869 virtual int SetSendBufferSize(int32 size) OVERRIDE;
871 // DatagramSocket implementation.
872 virtual void Close() OVERRIDE;
873 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
874 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
875 virtual const BoundNetLog& NetLog() const OVERRIDE;
877 // DatagramClientSocket implementation.
878 virtual int Connect(const IPEndPoint& address) OVERRIDE;
880 // AsyncSocket implementation.
881 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
882 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
884 void set_source_port(int port) { source_port_ = port; }
886 private:
887 bool connected_;
888 IPEndPoint peer_address_;
889 DeterministicSocketHelper helper_;
890 int source_port_; // Ephemeral source port.
892 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket);
895 // Mock TCP socket to be used in conjunction with DeterministicSocketData.
896 class DeterministicMockTCPClientSocket
897 : public MockClientSocket,
898 public AsyncSocket,
899 public DeterministicSocketData::Delegate,
900 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> {
901 public:
902 DeterministicMockTCPClientSocket(net::NetLog* net_log,
903 DeterministicSocketData* data);
904 virtual ~DeterministicMockTCPClientSocket();
906 // DeterministicSocketData::Delegate:
907 virtual bool WritePending() const OVERRIDE;
908 virtual bool ReadPending() const OVERRIDE;
909 virtual void CompleteWrite() OVERRIDE;
910 virtual int CompleteRead() OVERRIDE;
912 // Socket:
913 virtual int Write(IOBuffer* buf,
914 int buf_len,
915 const CompletionCallback& callback) OVERRIDE;
916 virtual int Read(IOBuffer* buf,
917 int buf_len,
918 const CompletionCallback& callback) OVERRIDE;
920 // StreamSocket:
921 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
922 virtual void Disconnect() OVERRIDE;
923 virtual bool IsConnected() const OVERRIDE;
924 virtual bool IsConnectedAndIdle() const OVERRIDE;
925 virtual bool WasEverUsed() const OVERRIDE;
926 virtual bool UsingTCPFastOpen() const OVERRIDE;
927 virtual bool WasNpnNegotiated() const OVERRIDE;
928 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
930 // AsyncSocket:
931 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
932 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
934 private:
935 DeterministicSocketHelper helper_;
937 DISALLOW_COPY_AND_ASSIGN(DeterministicMockTCPClientSocket);
940 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
941 public:
942 MockSSLClientSocket(scoped_ptr<ClientSocketHandle> transport_socket,
943 const HostPortPair& host_and_port,
944 const SSLConfig& ssl_config,
945 SSLSocketDataProvider* socket);
946 virtual ~MockSSLClientSocket();
948 // Socket implementation.
949 virtual int Read(IOBuffer* buf,
950 int buf_len,
951 const CompletionCallback& callback) OVERRIDE;
952 virtual int Write(IOBuffer* buf,
953 int buf_len,
954 const CompletionCallback& callback) OVERRIDE;
956 // StreamSocket implementation.
957 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
958 virtual void Disconnect() OVERRIDE;
959 virtual bool IsConnected() const OVERRIDE;
960 virtual bool WasEverUsed() const OVERRIDE;
961 virtual bool UsingTCPFastOpen() const OVERRIDE;
962 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
963 virtual bool WasNpnNegotiated() const OVERRIDE;
964 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
966 // SSLClientSocket implementation.
967 virtual bool InSessionCache() const OVERRIDE;
968 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE;
969 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
970 OVERRIDE;
971 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE;
972 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE;
973 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE;
974 virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
976 // This MockSocket does not implement the manual async IO feature.
977 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
978 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
980 virtual bool WasChannelIDSent() const OVERRIDE;
981 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE;
982 virtual ChannelIDService* GetChannelIDService() const OVERRIDE;
984 bool reached_connect() const { return reached_connect_; }
986 // Resumes the connection of a socket that was paused for testing.
987 // |connect_callback_| should be set before invoking this method.
988 void RestartPausedConnect();
990 private:
991 enum ConnectState {
992 STATE_NONE,
993 STATE_TRANSPORT_CONNECT,
994 STATE_TRANSPORT_CONNECT_COMPLETE,
995 STATE_SSL_CONNECT,
996 STATE_SSL_CONNECT_COMPLETE,
999 void OnIOComplete(int result);
1001 // Runs the state transistion loop.
1002 int DoConnectLoop(int result);
1004 int DoTransportConnect();
1005 int DoTransportConnectComplete(int result);
1006 int DoSSLConnect();
1007 int DoSSLConnectComplete(int result);
1009 scoped_ptr<ClientSocketHandle> transport_;
1010 SSLSocketDataProvider* data_;
1011 bool is_npn_state_set_;
1012 bool new_npn_value_;
1013 bool is_protocol_negotiated_set_;
1014 NextProto protocol_negotiated_;
1016 CompletionCallback connect_callback_;
1017 // Indicates what state of Connect the socket should enter.
1018 ConnectState next_connect_state_;
1019 // True if the Connect method has been called on the socket.
1020 bool reached_connect_;
1022 base::Closure handshake_completion_callback_;
1024 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_;
1026 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
1029 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
1030 public:
1031 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
1032 virtual ~MockUDPClientSocket();
1034 // Socket implementation.
1035 virtual int Read(IOBuffer* buf,
1036 int buf_len,
1037 const CompletionCallback& callback) OVERRIDE;
1038 virtual int Write(IOBuffer* buf,
1039 int buf_len,
1040 const CompletionCallback& callback) OVERRIDE;
1041 virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
1042 virtual int SetSendBufferSize(int32 size) OVERRIDE;
1044 // DatagramSocket implementation.
1045 virtual void Close() OVERRIDE;
1046 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
1047 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
1048 virtual const BoundNetLog& NetLog() const OVERRIDE;
1050 // DatagramClientSocket implementation.
1051 virtual int Connect(const IPEndPoint& address) OVERRIDE;
1053 // AsyncSocket implementation.
1054 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
1055 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
1057 void set_source_port(int port) { source_port_ = port;}
1059 private:
1060 int CompleteRead();
1062 void RunCallbackAsync(const CompletionCallback& callback, int result);
1063 void RunCallback(const CompletionCallback& callback, int result);
1065 bool connected_;
1066 SocketDataProvider* data_;
1067 int read_offset_;
1068 MockRead read_data_;
1069 bool need_read_data_;
1070 int source_port_; // Ephemeral source port.
1072 // Address of the "remote" peer we're connected to.
1073 IPEndPoint peer_addr_;
1075 // While an asynchronous IO is pending, we save our user-buffer state.
1076 scoped_refptr<IOBuffer> pending_buf_;
1077 int pending_buf_len_;
1078 CompletionCallback pending_callback_;
1080 BoundNetLog net_log_;
1082 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_;
1084 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket);
1087 class TestSocketRequest : public TestCompletionCallbackBase {
1088 public:
1089 TestSocketRequest(std::vector<TestSocketRequest*>* request_order,
1090 size_t* completion_count);
1091 virtual ~TestSocketRequest();
1093 ClientSocketHandle* handle() { return &handle_; }
1095 const net::CompletionCallback& callback() const { return callback_; }
1097 private:
1098 void OnComplete(int result);
1100 ClientSocketHandle handle_;
1101 std::vector<TestSocketRequest*>* request_order_;
1102 size_t* completion_count_;
1103 CompletionCallback callback_;
1105 DISALLOW_COPY_AND_ASSIGN(TestSocketRequest);
1108 class ClientSocketPoolTest {
1109 public:
1110 enum KeepAlive {
1111 KEEP_ALIVE,
1113 // A socket will be disconnected in addition to handle being reset.
1114 NO_KEEP_ALIVE,
1117 static const int kIndexOutOfBounds;
1118 static const int kRequestNotFound;
1120 ClientSocketPoolTest();
1121 ~ClientSocketPoolTest();
1123 template <typename PoolType>
1124 int StartRequestUsingPool(
1125 PoolType* socket_pool,
1126 const std::string& group_name,
1127 RequestPriority priority,
1128 const scoped_refptr<typename PoolType::SocketParams>& socket_params) {
1129 DCHECK(socket_pool);
1130 TestSocketRequest* request =
1131 new TestSocketRequest(&request_order_, &completion_count_);
1132 requests_.push_back(request);
1133 int rv = request->handle()->Init(group_name,
1134 socket_params,
1135 priority,
1136 request->callback(),
1137 socket_pool,
1138 BoundNetLog());
1139 if (rv != ERR_IO_PENDING)
1140 request_order_.push_back(request);
1141 return rv;
1144 // Provided there were n requests started, takes |index| in range 1..n
1145 // and returns order in which that request completed, in range 1..n,
1146 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound
1147 // if that request did not complete (for example was canceled).
1148 int GetOrderOfRequest(size_t index) const;
1150 // Resets first initialized socket handle from |requests_|. If found such
1151 // a handle, returns true.
1152 bool ReleaseOneConnection(KeepAlive keep_alive);
1154 // Releases connections until there is nothing to release.
1155 void ReleaseAllConnections(KeepAlive keep_alive);
1157 // Note that this uses 0-based indices, while GetOrderOfRequest takes and
1158 // returns 0-based indices.
1159 TestSocketRequest* request(int i) { return requests_[i]; }
1161 size_t requests_size() const { return requests_.size(); }
1162 ScopedVector<TestSocketRequest>* requests() { return &requests_; }
1163 size_t completion_count() const { return completion_count_; }
1165 private:
1166 ScopedVector<TestSocketRequest> requests_;
1167 std::vector<TestSocketRequest*> request_order_;
1168 size_t completion_count_;
1170 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolTest);
1173 class MockTransportSocketParams
1174 : public base::RefCounted<MockTransportSocketParams> {
1175 private:
1176 friend class base::RefCounted<MockTransportSocketParams>;
1177 ~MockTransportSocketParams() {}
1179 DISALLOW_COPY_AND_ASSIGN(MockTransportSocketParams);
1182 class MockTransportClientSocketPool : public TransportClientSocketPool {
1183 public:
1184 typedef MockTransportSocketParams SocketParams;
1186 class MockConnectJob {
1187 public:
1188 MockConnectJob(scoped_ptr<StreamSocket> socket,
1189 ClientSocketHandle* handle,
1190 const CompletionCallback& callback);
1191 ~MockConnectJob();
1193 int Connect();
1194 bool CancelHandle(const ClientSocketHandle* handle);
1196 private:
1197 void OnConnect(int rv);
1199 scoped_ptr<StreamSocket> socket_;
1200 ClientSocketHandle* handle_;
1201 CompletionCallback user_callback_;
1203 DISALLOW_COPY_AND_ASSIGN(MockConnectJob);
1206 MockTransportClientSocketPool(int max_sockets,
1207 int max_sockets_per_group,
1208 ClientSocketPoolHistograms* histograms,
1209 ClientSocketFactory* socket_factory);
1211 virtual ~MockTransportClientSocketPool();
1213 RequestPriority last_request_priority() const {
1214 return last_request_priority_;
1216 int release_count() const { return release_count_; }
1217 int cancel_count() const { return cancel_count_; }
1219 // TransportClientSocketPool implementation.
1220 virtual int RequestSocket(const std::string& group_name,
1221 const void* socket_params,
1222 RequestPriority priority,
1223 ClientSocketHandle* handle,
1224 const CompletionCallback& callback,
1225 const BoundNetLog& net_log) OVERRIDE;
1227 virtual void CancelRequest(const std::string& group_name,
1228 ClientSocketHandle* handle) OVERRIDE;
1229 virtual void ReleaseSocket(const std::string& group_name,
1230 scoped_ptr<StreamSocket> socket,
1231 int id) OVERRIDE;
1233 private:
1234 ClientSocketFactory* client_socket_factory_;
1235 ScopedVector<MockConnectJob> job_list_;
1236 RequestPriority last_request_priority_;
1237 int release_count_;
1238 int cancel_count_;
1240 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool);
1243 class DeterministicMockClientSocketFactory : public ClientSocketFactory {
1244 public:
1245 DeterministicMockClientSocketFactory();
1246 virtual ~DeterministicMockClientSocketFactory();
1248 void AddSocketDataProvider(DeterministicSocketData* socket);
1249 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
1250 void ResetNextMockIndexes();
1252 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory
1253 // created.
1254 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const;
1256 SocketDataProviderArray<DeterministicSocketData>& mock_data() {
1257 return mock_data_;
1259 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() {
1260 return tcp_client_sockets_;
1262 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() {
1263 return udp_client_sockets_;
1266 // ClientSocketFactory
1267 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
1268 DatagramSocket::BindType bind_type,
1269 const RandIntCallback& rand_int_cb,
1270 NetLog* net_log,
1271 const NetLog::Source& source) OVERRIDE;
1272 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
1273 const AddressList& addresses,
1274 NetLog* net_log,
1275 const NetLog::Source& source) OVERRIDE;
1276 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
1277 scoped_ptr<ClientSocketHandle> transport_socket,
1278 const HostPortPair& host_and_port,
1279 const SSLConfig& ssl_config,
1280 const SSLClientSocketContext& context) OVERRIDE;
1281 virtual void ClearSSLSessionCache() OVERRIDE;
1283 private:
1284 SocketDataProviderArray<DeterministicSocketData> mock_data_;
1285 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
1287 // Store pointers to handed out sockets in case the test wants to get them.
1288 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_;
1289 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_;
1290 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
1292 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory);
1295 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
1296 public:
1297 MockSOCKSClientSocketPool(int max_sockets,
1298 int max_sockets_per_group,
1299 ClientSocketPoolHistograms* histograms,
1300 TransportClientSocketPool* transport_pool);
1302 virtual ~MockSOCKSClientSocketPool();
1304 // SOCKSClientSocketPool implementation.
1305 virtual int RequestSocket(const std::string& group_name,
1306 const void* socket_params,
1307 RequestPriority priority,
1308 ClientSocketHandle* handle,
1309 const CompletionCallback& callback,
1310 const BoundNetLog& net_log) OVERRIDE;
1312 virtual void CancelRequest(const std::string& group_name,
1313 ClientSocketHandle* handle) OVERRIDE;
1314 virtual void ReleaseSocket(const std::string& group_name,
1315 scoped_ptr<StreamSocket> socket,
1316 int id) OVERRIDE;
1318 private:
1319 TransportClientSocketPool* const transport_pool_;
1321 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
1324 // Constants for a successful SOCKS v5 handshake.
1325 extern const char kSOCKS5GreetRequest[];
1326 extern const int kSOCKS5GreetRequestLength;
1328 extern const char kSOCKS5GreetResponse[];
1329 extern const int kSOCKS5GreetResponseLength;
1331 extern const char kSOCKS5OkRequest[];
1332 extern const int kSOCKS5OkRequestLength;
1334 extern const char kSOCKS5OkResponse[];
1335 extern const int kSOCKS5OkResponseLength;
1337 } // namespace net
1339 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_