Revert of Add CompleteRead to SequencedSocketData and convert all but 3 tests (patchs...
[chromium-blink-merge.git] / net / socket / socket_test_util.h
blobb4584ad956384b7ac97d934fd46afb0a433d1087
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 "base/time/time.h"
22 #include "net/base/address_list.h"
23 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.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/log/net_log.h"
29 #include "net/socket/client_socket_factory.h"
30 #include "net/socket/client_socket_handle.h"
31 #include "net/socket/socks_client_socket_pool.h"
32 #include "net/socket/ssl_client_socket.h"
33 #include "net/socket/ssl_client_socket_pool.h"
34 #include "net/socket/transport_client_socket_pool.h"
35 #include "net/ssl/ssl_config_service.h"
36 #include "net/udp/datagram_client_socket.h"
37 #include "testing/gtest/include/gtest/gtest.h"
39 namespace net {
41 enum {
42 // A private network error code used by the socket test utility classes.
43 // If the |result| member of a MockRead is
44 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a
45 // marker that indicates the peer will close the connection after the next
46 // MockRead. The other members of that MockRead are ignored.
47 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000,
50 class AsyncSocket;
51 class ChannelIDService;
52 class MockClientSocket;
53 class SSLClientSocket;
54 class StreamSocket;
56 enum IoMode {
57 ASYNC,
58 SYNCHRONOUS
61 struct MockConnect {
62 // Asynchronous connection success.
63 // Creates a MockConnect with |mode| ASYC, |result| OK, and
64 // |peer_addr| 192.0.2.33.
65 MockConnect();
66 // Creates a MockConnect with the specified mode and result, with
67 // |peer_addr| 192.0.2.33.
68 MockConnect(IoMode io_mode, int r);
69 MockConnect(IoMode io_mode, int r, IPEndPoint addr);
70 ~MockConnect();
72 IoMode mode;
73 int result;
74 IPEndPoint peer_addr;
77 // MockRead and MockWrite shares the same interface and members, but we'd like
78 // to have distinct types because we don't want to have them used
79 // interchangably. To do this, a struct template is defined, and MockRead and
80 // MockWrite are instantiated by using this template. Template parameter |type|
81 // is not used in the struct definition (it purely exists for creating a new
82 // type).
84 // |data| in MockRead and MockWrite has different meanings: |data| in MockRead
85 // is the data returned from the socket when MockTCPClientSocket::Read() is
86 // attempted, while |data| in MockWrite is the expected data that should be
87 // given in MockTCPClientSocket::Write().
88 enum MockReadWriteType {
89 MOCK_READ,
90 MOCK_WRITE
93 template <MockReadWriteType type>
94 struct MockReadWrite {
95 // Flag to indicate that the message loop should be terminated.
96 enum {
97 STOPLOOP = 1 << 31
100 // Default
101 MockReadWrite()
102 : mode(SYNCHRONOUS),
103 result(0),
104 data(NULL),
105 data_len(0),
106 sequence_number(0) {}
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) {}
116 // Read/write failure (no data), with sequence information.
117 MockReadWrite(IoMode io_mode, int result, int seq)
118 : mode(io_mode),
119 result(result),
120 data(NULL),
121 data_len(0),
122 sequence_number(seq) {}
124 // Asynchronous read/write success (inferred data length).
125 explicit MockReadWrite(const char* data)
126 : mode(ASYNC),
127 result(0),
128 data(data),
129 data_len(strlen(data)),
130 sequence_number(0) {}
132 // Read/write success (inferred data length).
133 MockReadWrite(IoMode io_mode, const char* data)
134 : mode(io_mode),
135 result(0),
136 data(data),
137 data_len(strlen(data)),
138 sequence_number(0) {}
140 // Read/write success.
141 MockReadWrite(IoMode io_mode, const char* data, int data_len)
142 : mode(io_mode),
143 result(0),
144 data(data),
145 data_len(data_len),
146 sequence_number(0) {}
148 // Read/write success (inferred data length) with sequence information.
149 MockReadWrite(IoMode io_mode, int seq, const char* data)
150 : mode(io_mode),
151 result(0),
152 data(data),
153 data_len(strlen(data)),
154 sequence_number(seq) {}
156 // Read/write success with sequence information.
157 MockReadWrite(IoMode io_mode, const char* data, int data_len, int seq)
158 : mode(io_mode),
159 result(0),
160 data(data),
161 data_len(data_len),
162 sequence_number(seq) {}
164 IoMode mode;
165 int result;
166 const char* data;
167 int data_len;
169 // For OrderedSocketData, which only allows reads to occur in a particular
170 // sequence. If a read occurs before the given |sequence_number| is reached,
171 // an ERR_IO_PENDING is returned.
172 int sequence_number; // The sequence number at which a read is allowed
173 // to occur.
176 typedef MockReadWrite<MOCK_READ> MockRead;
177 typedef MockReadWrite<MOCK_WRITE> MockWrite;
179 struct MockWriteResult {
180 MockWriteResult(IoMode io_mode, int result) : mode(io_mode), result(result) {}
182 IoMode mode;
183 int result;
186 // The SocketDataProvider is an interface used by the MockClientSocket
187 // for getting data about individual reads and writes on the socket.
188 class SocketDataProvider {
189 public:
190 SocketDataProvider() : socket_(NULL) {}
192 virtual ~SocketDataProvider() {}
194 // Returns the buffer and result code for the next simulated read.
195 // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller
196 // that it will be called via the AsyncSocket::OnReadComplete()
197 // function at a later time.
198 virtual MockRead OnRead() = 0;
199 virtual MockWriteResult OnWrite(const std::string& data) = 0;
200 virtual void Reset() = 0;
201 virtual bool AllReadDataConsumed() const = 0;
202 virtual bool AllWriteDataConsumed() const = 0;
204 // Accessor for the socket which is using the SocketDataProvider.
205 AsyncSocket* socket() { return socket_; }
206 void set_socket(AsyncSocket* socket) { socket_ = socket; }
208 MockConnect connect_data() const { return connect_; }
209 void set_connect_data(const MockConnect& connect) { connect_ = connect; }
211 private:
212 MockConnect connect_;
213 AsyncSocket* socket_;
215 DISALLOW_COPY_AND_ASSIGN(SocketDataProvider);
218 // The AsyncSocket is an interface used by the SocketDataProvider to
219 // complete the asynchronous read operation.
220 class AsyncSocket {
221 public:
222 // If an async IO is pending because the SocketDataProvider returned
223 // ERR_IO_PENDING, then the AsyncSocket waits until this OnReadComplete
224 // is called to complete the asynchronous read operation.
225 // data.async is ignored, and this read is completed synchronously as
226 // part of this call.
227 // TODO(rch): this should take a StringPiece since most of the fields
228 // are ignored.
229 virtual void OnReadComplete(const MockRead& data) = 0;
230 // If an async IO is pending because the SocketDataProvider returned
231 // ERR_IO_PENDING, then the AsyncSocket waits until this OnReadComplete
232 // is called to complete the asynchronous read operation.
233 virtual void OnWriteComplete(int rv) = 0;
234 virtual void OnConnectComplete(const MockConnect& data) = 0;
237 // StaticSocketDataHelper manages a list of reads and writes.
238 class StaticSocketDataHelper {
239 public:
240 StaticSocketDataHelper(MockRead* reads,
241 size_t reads_count,
242 MockWrite* writes,
243 size_t writes_count);
244 ~StaticSocketDataHelper();
246 // These functions get access to the next available read and write data,
247 // or null if there is no more data available.
248 const MockRead& PeekRead() const;
249 const MockWrite& PeekWrite() const;
251 // Returns the current read or write , and then advances to the next one.
252 const MockRead& AdvanceRead();
253 const MockWrite& AdvanceWrite();
255 // Resets the read and write indexes to 0.
256 void Reset();
258 // Returns true if |data| is valid data for the next write. In order
259 // to support short writes, the next write may be longer than |data|
260 // in which case this method will still return true.
261 bool VerifyWriteData(const std::string& data);
263 // Return true if all read data has been consumed.
264 bool AllReadDataConsumed() const;
266 // Return true if all write data has been consumed.
267 bool AllWriteDataConsumed() const;
269 size_t read_index() const { return read_index_; }
270 size_t write_index() const { return write_index_; }
271 size_t read_count() const { return read_count_; }
272 size_t write_count() const { return write_count_; }
274 private:
275 MockRead* reads_;
276 size_t read_index_;
277 size_t read_count_;
278 MockWrite* writes_;
279 size_t write_index_;
280 size_t write_count_;
282 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper);
285 // SocketDataProvider which responds based on static tables of mock reads and
286 // writes.
287 class StaticSocketDataProvider : public SocketDataProvider {
288 public:
289 StaticSocketDataProvider();
290 StaticSocketDataProvider(MockRead* reads,
291 size_t reads_count,
292 MockWrite* writes,
293 size_t writes_count);
294 ~StaticSocketDataProvider() override;
296 virtual void CompleteRead() {}
298 // SocketDataProvider implementation.
299 MockRead OnRead() override;
300 MockWriteResult OnWrite(const std::string& data) override;
301 void Reset() override;
302 bool AllReadDataConsumed() const override;
303 bool AllWriteDataConsumed() const override;
305 size_t read_index() const { return helper_.read_index(); }
306 size_t write_index() const { return helper_.write_index(); }
307 size_t read_count() const { return helper_.read_count(); }
308 size_t write_count() const { return helper_.write_count(); }
310 protected:
311 StaticSocketDataHelper* helper() { return &helper_; }
313 private:
314 StaticSocketDataHelper helper_;
316 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
319 // SocketDataProvider which can make decisions about next mock reads based on
320 // received writes. It can also be used to enforce order of operations, for
321 // example that tested code must send the "Hello!" message before receiving
322 // response. This is useful for testing conversation-like protocols like FTP.
323 class DynamicSocketDataProvider : public SocketDataProvider {
324 public:
325 DynamicSocketDataProvider();
326 ~DynamicSocketDataProvider() override;
328 int short_read_limit() const { return short_read_limit_; }
329 void set_short_read_limit(int limit) { short_read_limit_ = limit; }
331 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; }
333 // SocketDataProvider implementation.
334 MockRead OnRead() override;
335 MockWriteResult OnWrite(const std::string& data) override = 0;
336 void Reset() override;
338 protected:
339 // The next time there is a read from this socket, it will return |data|.
340 // Before calling SimulateRead next time, the previous data must be consumed.
341 void SimulateRead(const char* data, size_t length);
342 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); }
344 private:
345 std::deque<MockRead> reads_;
347 // Max number of bytes we will read at a time. 0 means no limit.
348 int short_read_limit_;
350 // If true, we'll not require the client to consume all data before we
351 // mock the next read.
352 bool allow_unconsumed_reads_;
354 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider);
357 // SSLSocketDataProviders only need to keep track of the return code from calls
358 // to Connect().
359 struct SSLSocketDataProvider {
360 SSLSocketDataProvider(IoMode mode, int result);
361 ~SSLSocketDataProvider();
363 void SetNextProto(NextProto proto);
365 MockConnect connect;
366 SSLClientSocket::NextProtoStatus next_proto_status;
367 std::string next_proto;
368 NextProtoVector next_protos_expected_in_ssl_config;
369 bool client_cert_sent;
370 SSLCertRequestInfo* cert_request_info;
371 scoped_refptr<X509Certificate> cert;
372 bool channel_id_sent;
373 ChannelIDService* channel_id_service;
374 int connection_status;
377 // A DataProvider where the client must write a request before the reads (e.g.
378 // the response) will complete.
379 class DelayedSocketData : public StaticSocketDataProvider {
380 public:
381 // |write_delay| the number of MockWrites to complete before allowing
382 // a MockRead to complete.
383 // |reads| the list of MockRead completions.
384 // |writes| the list of MockWrite completions.
385 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
386 // MockRead(true, 0, 0);
387 DelayedSocketData(int write_delay,
388 MockRead* reads,
389 size_t reads_count,
390 MockWrite* writes,
391 size_t writes_count);
393 // |connect| the result for the connect phase.
394 // |reads| the list of MockRead completions.
395 // |write_delay| the number of MockWrites to complete before allowing
396 // a MockRead to complete.
397 // |writes| the list of MockWrite completions.
398 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
399 // MockRead(true, 0, 0);
400 DelayedSocketData(const MockConnect& connect,
401 int write_delay,
402 MockRead* reads,
403 size_t reads_count,
404 MockWrite* writes,
405 size_t writes_count);
406 ~DelayedSocketData() override;
408 void ForceNextRead();
410 // StaticSocketDataProvider:
411 MockRead OnRead() override;
412 MockWriteResult OnWrite(const std::string& data) override;
413 void Reset() override;
414 void CompleteRead() override;
416 private:
417 int write_delay_;
418 bool read_in_progress_;
420 base::WeakPtrFactory<DelayedSocketData> weak_factory_;
422 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData);
425 // A DataProvider where the reads are ordered.
426 // If a read is requested before its sequence number is reached, we return an
427 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to
428 // wait).
429 // The sequence number is incremented on every read and write operation.
430 // The message loop may be interrupted by setting the high bit of the sequence
431 // number in the MockRead's sequence number. When that MockRead is reached,
432 // we post a Quit message to the loop. This allows us to interrupt the reading
433 // of data before a complete message has arrived, and provides support for
434 // testing server push when the request is issued while the response is in the
435 // middle of being received.
436 class OrderedSocketData : public StaticSocketDataProvider {
437 public:
438 // |reads| the list of MockRead completions.
439 // |writes| the list of MockWrite completions.
440 // Note: All MockReads and MockWrites must be async.
441 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
442 // MockRead(true, 0, 0);
443 OrderedSocketData(MockRead* reads,
444 size_t reads_count,
445 MockWrite* writes,
446 size_t writes_count);
447 ~OrderedSocketData() override;
449 // |connect| the result for the connect phase.
450 // |reads| the list of MockRead completions.
451 // |writes| the list of MockWrite completions.
452 // Note: All MockReads and MockWrites must be async.
453 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
454 // MockRead(true, 0, 0);
455 OrderedSocketData(const MockConnect& connect,
456 MockRead* reads,
457 size_t reads_count,
458 MockWrite* writes,
459 size_t writes_count);
461 // Posts a quit message to the current message loop, if one is running.
462 void EndLoop();
464 // StaticSocketDataProvider:
465 MockRead OnRead() override;
466 MockWriteResult OnWrite(const std::string& data) override;
467 void Reset() override;
468 void CompleteRead() override;
470 private:
471 int sequence_number_;
472 int loop_stop_stage_;
473 bool blocked_;
475 base::WeakPtrFactory<OrderedSocketData> weak_factory_;
477 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData);
480 // Uses the sequence_number field in the mock reads and writes to
481 // complete the operations in a specified order.
482 class SequencedSocketData : public SocketDataProvider {
483 public:
484 // |reads| is the list of MockRead completions.
485 // |writes| is the list of MockWrite completions.
486 SequencedSocketData(MockRead* reads,
487 size_t reads_count,
488 MockWrite* writes,
489 size_t writes_count);
491 // |connect| is the result for the connect phase.
492 // |reads| is the list of MockRead completions.
493 // |writes| is the list of MockWrite completions.
494 SequencedSocketData(const MockConnect& connect,
495 MockRead* reads,
496 size_t reads_count,
497 MockWrite* writes,
498 size_t writes_count);
500 ~SequencedSocketData() override;
502 // SocketDataProviderBase implementation.
503 MockRead OnRead() override;
504 MockWriteResult OnWrite(const std::string& data) override;
505 void Reset() override;
506 bool AllReadDataConsumed() const override;
507 bool AllWriteDataConsumed() const override;
509 private:
510 // Defines the state for the read or write path.
511 enum IoState {
512 IDLE, // No async operation is in progress.
513 PENDING, // An async operation in waiting for another opteration to
514 // complete.
515 COMPLETING, // A task has been posted to complet an async operation.
517 void OnReadComplete();
518 void OnWriteComplete();
520 void MaybePostReadCompleteTask();
521 void MaybePostWriteCompleteTask();
523 StaticSocketDataHelper helper_;
524 int sequence_number_;
525 IoState read_state_;
526 IoState write_state_;
528 base::WeakPtrFactory<SequencedSocketData> weak_factory_;
530 DISALLOW_COPY_AND_ASSIGN(SequencedSocketData);
533 class DeterministicMockTCPClientSocket;
535 // This class gives the user full control over the network activity,
536 // specifically the timing of the COMPLETION of I/O operations. Regardless of
537 // the order in which I/O operations are initiated, this class ensures that they
538 // complete in the correct order.
540 // Network activity is modeled as a sequence of numbered steps which is
541 // incremented whenever an I/O operation completes. This can happen under two
542 // different circumstances:
544 // 1) Performing a synchronous I/O operation. (Invoking Read() or Write()
545 // when the corresponding MockRead or MockWrite is marked !async).
546 // 2) Running the Run() method of this class. The run method will invoke
547 // the current MessageLoop, running all pending events, and will then
548 // invoke any pending IO callbacks.
550 // In addition, this class allows for I/O processing to "stop" at a specified
551 // step, by calling SetStop(int) or StopAfter(int). Initiating an I/O operation
552 // by calling Read() or Write() while stopped is permitted if the operation is
553 // asynchronous. It is an error to perform synchronous I/O while stopped.
555 // When creating the MockReads and MockWrites, note that the sequence number
556 // refers to the number of the step in which the I/O will complete. In the
557 // case of synchronous I/O, this will be the same step as the I/O is initiated.
558 // However, in the case of asynchronous I/O, this I/O may be initiated in
559 // a much earlier step. Furthermore, when the a Read() or Write() is separated
560 // from its completion by other Read() or Writes()'s, it can not be marked
561 // synchronous. If it is, ERR_UNUEXPECTED will be returned indicating that a
562 // synchronous Read() or Write() could not be completed synchronously because of
563 // the specific ordering constraints.
565 // Sequence numbers are preserved across both reads and writes. There should be
566 // no gaps in sequence numbers, and no repeated sequence numbers. i.e.
567 // MockRead reads[] = {
568 // MockRead(false, "first read", length, 0) // sync
569 // MockRead(true, "second read", length, 2) // async
570 // };
571 // MockWrite writes[] = {
572 // MockWrite(true, "first write", length, 1), // async
573 // MockWrite(false, "second write", length, 3), // sync
574 // };
576 // Example control flow:
577 // Read() is called. The current step is 0. The first available read is
578 // synchronous, so the call to Read() returns length. The current step is
579 // now 1. Next, Read() is called again. The next available read can
580 // not be completed until step 2, so Read() returns ERR_IO_PENDING. The current
581 // step is still 1. Write is called(). The first available write is able to
582 // complete in this step, but is marked asynchronous. Write() returns
583 // ERR_IO_PENDING. The current step is still 1. At this point RunFor(1) is
584 // called which will cause the write callback to be invoked, and will then
585 // stop. The current state is now 2. RunFor(1) is called again, which
586 // causes the read callback to be invoked, and will then stop. Then current
587 // step is 2. Write() is called again. Then next available write is
588 // synchronous so the call to Write() returns length.
590 // For examples of how to use this class, see:
591 // deterministic_socket_data_unittests.cc
592 class DeterministicSocketData : public StaticSocketDataProvider {
593 public:
594 // The Delegate is an abstract interface which handles the communication from
595 // the DeterministicSocketData to the Deterministic MockSocket. The
596 // MockSockets directly store a pointer to the DeterministicSocketData,
597 // whereas the DeterministicSocketData only stores a pointer to the
598 // abstract Delegate interface.
599 class Delegate {
600 public:
601 // Returns true if there is currently a write pending. That is to say, if
602 // an asynchronous write has been started but the callback has not been
603 // invoked.
604 virtual bool WritePending() const = 0;
605 // Returns true if there is currently a read pending. That is to say, if
606 // an asynchronous read has been started but the callback has not been
607 // invoked.
608 virtual bool ReadPending() const = 0;
609 // Called to complete an asynchronous write to execute the write callback.
610 virtual void CompleteWrite() = 0;
611 // Called to complete an asynchronous read to execute the read callback.
612 virtual int CompleteRead() = 0;
614 protected:
615 virtual ~Delegate() {}
618 // |reads| the list of MockRead completions.
619 // |writes| the list of MockWrite completions.
620 DeterministicSocketData(MockRead* reads,
621 size_t reads_count,
622 MockWrite* writes,
623 size_t writes_count);
624 ~DeterministicSocketData() override;
626 // Consume all the data up to the give stop point (via SetStop()).
627 void Run();
629 // Set the stop point to be |steps| from now, and then invoke Run().
630 void RunFor(int steps);
632 // Stop at step |seq|, which must be in the future.
633 virtual void SetStop(int seq);
635 // Stop |seq| steps after the current step.
636 virtual void StopAfter(int seq);
637 bool stopped() const { return stopped_; }
638 void SetStopped(bool val) { stopped_ = val; }
639 MockRead& current_read() { return current_read_; }
640 MockWrite& current_write() { return current_write_; }
641 int sequence_number() const { return sequence_number_; }
642 void set_delegate(base::WeakPtr<Delegate> delegate) { delegate_ = delegate; }
644 // StaticSocketDataProvider:
646 // When the socket calls Read(), that calls OnRead(), and expects either
647 // ERR_IO_PENDING or data.
648 MockRead OnRead() override;
650 // When the socket calls Write(), it always completes synchronously. OnWrite()
651 // checks to make sure the written data matches the expected data. The
652 // callback will not be invoked until its sequence number is reached.
653 MockWriteResult OnWrite(const std::string& data) override;
654 void Reset() override;
655 void CompleteRead() override {}
657 private:
658 // Invoke the read and write callbacks, if the timing is appropriate.
659 void InvokeCallbacks();
661 void NextStep();
663 void VerifyCorrectSequenceNumbers(MockRead* reads,
664 size_t reads_count,
665 MockWrite* writes,
666 size_t writes_count);
668 int sequence_number_;
669 MockRead current_read_;
670 MockWrite current_write_;
671 int stopping_sequence_number_;
672 bool stopped_;
673 base::WeakPtr<Delegate> delegate_;
674 bool print_debug_;
675 bool is_running_;
678 // Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}StreamSocket
679 // objects get instantiated, they take their data from the i'th element of this
680 // array.
681 template <typename T>
682 class SocketDataProviderArray {
683 public:
684 SocketDataProviderArray() : next_index_(0) {}
686 T* GetNext() {
687 DCHECK_LT(next_index_, data_providers_.size());
688 return data_providers_[next_index_++];
691 void Add(T* data_provider) {
692 DCHECK(data_provider);
693 data_providers_.push_back(data_provider);
696 size_t next_index() { return next_index_; }
698 void ResetNextIndex() { next_index_ = 0; }
700 private:
701 // Index of the next |data_providers_| element to use. Not an iterator
702 // because those are invalidated on vector reallocation.
703 size_t next_index_;
705 // SocketDataProviders to be returned.
706 std::vector<T*> data_providers_;
709 class MockUDPClientSocket;
710 class MockTCPClientSocket;
711 class MockSSLClientSocket;
713 // ClientSocketFactory which contains arrays of sockets of each type.
714 // You should first fill the arrays using AddMock{SSL,}Socket. When the factory
715 // is asked to create a socket, it takes next entry from appropriate array.
716 // You can use ResetNextMockIndexes to reset that next entry index for all mock
717 // socket types.
718 class MockClientSocketFactory : public ClientSocketFactory {
719 public:
720 MockClientSocketFactory();
721 ~MockClientSocketFactory() override;
723 void AddSocketDataProvider(SocketDataProvider* socket);
724 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
725 void ResetNextMockIndexes();
727 SocketDataProviderArray<SocketDataProvider>& mock_data() {
728 return mock_data_;
731 // ClientSocketFactory
732 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
733 DatagramSocket::BindType bind_type,
734 const RandIntCallback& rand_int_cb,
735 NetLog* net_log,
736 const NetLog::Source& source) override;
737 scoped_ptr<StreamSocket> CreateTransportClientSocket(
738 const AddressList& addresses,
739 NetLog* net_log,
740 const NetLog::Source& source) override;
741 scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
742 scoped_ptr<ClientSocketHandle> transport_socket,
743 const HostPortPair& host_and_port,
744 const SSLConfig& ssl_config,
745 const SSLClientSocketContext& context) override;
746 void ClearSSLSessionCache() override;
748 private:
749 SocketDataProviderArray<SocketDataProvider> mock_data_;
750 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
753 class MockClientSocket : public SSLClientSocket {
754 public:
755 // Value returned by GetTLSUniqueChannelBinding().
756 static const char kTlsUnique[];
758 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
759 // unique socket IDs.
760 explicit MockClientSocket(const BoundNetLog& net_log);
762 // Socket implementation.
763 int Read(IOBuffer* buf,
764 int buf_len,
765 const CompletionCallback& callback) override = 0;
766 int Write(IOBuffer* buf,
767 int buf_len,
768 const CompletionCallback& callback) override = 0;
769 int SetReceiveBufferSize(int32 size) override;
770 int SetSendBufferSize(int32 size) override;
772 // StreamSocket implementation.
773 int Connect(const CompletionCallback& callback) override = 0;
774 void Disconnect() override;
775 bool IsConnected() const override;
776 bool IsConnectedAndIdle() const override;
777 int GetPeerAddress(IPEndPoint* address) const override;
778 int GetLocalAddress(IPEndPoint* address) const override;
779 const BoundNetLog& NetLog() const override;
780 void SetSubresourceSpeculation() override {}
781 void SetOmniboxSpeculation() override {}
783 // SSLClientSocket implementation.
784 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
785 int ExportKeyingMaterial(const base::StringPiece& label,
786 bool has_context,
787 const base::StringPiece& context,
788 unsigned char* out,
789 unsigned int outlen) override;
790 int GetTLSUniqueChannelBinding(std::string* out) override;
791 NextProtoStatus GetNextProto(std::string* proto) const override;
792 ChannelIDService* GetChannelIDService() const override;
794 protected:
795 ~MockClientSocket() override;
796 void RunCallbackAsync(const CompletionCallback& callback, int result);
797 void RunCallback(const CompletionCallback& callback, int result);
799 // SSLClientSocket implementation.
800 scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
801 const override;
803 // True if Connect completed successfully and Disconnect hasn't been called.
804 bool connected_;
806 // Address of the "remote" peer we're connected to.
807 IPEndPoint peer_addr_;
809 BoundNetLog net_log_;
811 private:
812 base::WeakPtrFactory<MockClientSocket> weak_factory_;
814 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
817 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
818 public:
819 MockTCPClientSocket(const AddressList& addresses,
820 net::NetLog* net_log,
821 SocketDataProvider* socket);
822 ~MockTCPClientSocket() override;
824 const AddressList& addresses() const { return addresses_; }
826 // Socket implementation.
827 int Read(IOBuffer* buf,
828 int buf_len,
829 const CompletionCallback& callback) override;
830 int Write(IOBuffer* buf,
831 int buf_len,
832 const CompletionCallback& callback) override;
834 // StreamSocket implementation.
835 int Connect(const CompletionCallback& callback) override;
836 void Disconnect() override;
837 bool IsConnected() const override;
838 bool IsConnectedAndIdle() const override;
839 int GetPeerAddress(IPEndPoint* address) const override;
840 bool WasEverUsed() const override;
841 bool UsingTCPFastOpen() const override;
842 bool WasNpnNegotiated() const override;
843 bool GetSSLInfo(SSLInfo* ssl_info) override;
845 // AsyncSocket:
846 void OnReadComplete(const MockRead& data) override;
847 void OnWriteComplete(int rv) override;
848 void OnConnectComplete(const MockConnect& data) override;
850 private:
851 int CompleteRead();
853 AddressList addresses_;
855 SocketDataProvider* data_;
856 int read_offset_;
857 MockRead read_data_;
858 bool need_read_data_;
860 // True if the peer has closed the connection. This allows us to simulate
861 // the recv(..., MSG_PEEK) call in the IsConnectedAndIdle method of the real
862 // TCPClientSocket.
863 bool peer_closed_connection_;
865 // While an asynchronous read is pending, we save our user-buffer state.
866 scoped_refptr<IOBuffer> pending_read_buf_;
867 int pending_read_buf_len_;
868 CompletionCallback pending_read_callback_;
869 CompletionCallback pending_write_callback_;
870 bool was_used_to_convey_data_;
872 DISALLOW_COPY_AND_ASSIGN(MockTCPClientSocket);
875 // DeterministicSocketHelper is a helper class that can be used
876 // to simulate Socket::Read() and Socket::Write()
877 // using deterministic |data|.
878 // Note: This is provided as a common helper class because
879 // of the inheritance hierarchy of DeterministicMock[UDP,TCP]ClientSocket and a
880 // desire not to introduce an additional common base class.
881 class DeterministicSocketHelper {
882 public:
883 DeterministicSocketHelper(NetLog* net_log, DeterministicSocketData* data);
884 virtual ~DeterministicSocketHelper();
886 bool write_pending() const { return write_pending_; }
887 bool read_pending() const { return read_pending_; }
889 void CompleteWrite();
890 int CompleteRead();
892 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
893 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
895 const BoundNetLog& net_log() const { return net_log_; }
897 bool was_used_to_convey_data() const { return was_used_to_convey_data_; }
899 bool peer_closed_connection() const { return peer_closed_connection_; }
901 DeterministicSocketData* data() const { return data_; }
903 private:
904 bool write_pending_;
905 CompletionCallback write_callback_;
906 int write_result_;
908 MockRead read_data_;
910 IOBuffer* read_buf_;
911 int read_buf_len_;
912 bool read_pending_;
913 CompletionCallback read_callback_;
914 DeterministicSocketData* data_;
915 bool was_used_to_convey_data_;
916 bool peer_closed_connection_;
917 BoundNetLog net_log_;
920 // Mock UDP socket to be used in conjunction with DeterministicSocketData.
921 class DeterministicMockUDPClientSocket
922 : public DatagramClientSocket,
923 public AsyncSocket,
924 public DeterministicSocketData::Delegate,
925 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> {
926 public:
927 DeterministicMockUDPClientSocket(net::NetLog* net_log,
928 DeterministicSocketData* data);
929 ~DeterministicMockUDPClientSocket() override;
931 // DeterministicSocketData::Delegate:
932 bool WritePending() const override;
933 bool ReadPending() const override;
934 void CompleteWrite() override;
935 int CompleteRead() override;
937 // Socket implementation.
938 int Read(IOBuffer* buf,
939 int buf_len,
940 const CompletionCallback& callback) override;
941 int Write(IOBuffer* buf,
942 int buf_len,
943 const CompletionCallback& callback) override;
944 int SetReceiveBufferSize(int32 size) override;
945 int SetSendBufferSize(int32 size) override;
947 // DatagramSocket implementation.
948 void Close() override;
949 int GetPeerAddress(IPEndPoint* address) const override;
950 int GetLocalAddress(IPEndPoint* address) const override;
951 const BoundNetLog& NetLog() const override;
953 // DatagramClientSocket implementation.
954 int Connect(const IPEndPoint& address) override;
956 // AsyncSocket implementation.
957 void OnReadComplete(const MockRead& data) override;
958 void OnWriteComplete(int rv) override;
959 void OnConnectComplete(const MockConnect& data) override;
961 void set_source_port(uint16 port) { source_port_ = port; }
963 private:
964 bool connected_;
965 IPEndPoint peer_address_;
966 DeterministicSocketHelper helper_;
967 uint16 source_port_; // Ephemeral source port.
969 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket);
972 // Mock TCP socket to be used in conjunction with DeterministicSocketData.
973 class DeterministicMockTCPClientSocket
974 : public MockClientSocket,
975 public AsyncSocket,
976 public DeterministicSocketData::Delegate,
977 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> {
978 public:
979 DeterministicMockTCPClientSocket(net::NetLog* net_log,
980 DeterministicSocketData* data);
981 ~DeterministicMockTCPClientSocket() override;
983 // DeterministicSocketData::Delegate:
984 bool WritePending() const override;
985 bool ReadPending() const override;
986 void CompleteWrite() override;
987 int CompleteRead() override;
989 // Socket:
990 int Write(IOBuffer* buf,
991 int buf_len,
992 const CompletionCallback& callback) override;
993 int Read(IOBuffer* buf,
994 int buf_len,
995 const CompletionCallback& callback) override;
997 // StreamSocket:
998 int Connect(const CompletionCallback& callback) override;
999 void Disconnect() override;
1000 bool IsConnected() const override;
1001 bool IsConnectedAndIdle() const override;
1002 bool WasEverUsed() const override;
1003 bool UsingTCPFastOpen() const override;
1004 bool WasNpnNegotiated() const override;
1005 bool GetSSLInfo(SSLInfo* ssl_info) override;
1007 // AsyncSocket:
1008 void OnReadComplete(const MockRead& data) override;
1009 void OnWriteComplete(int rv) override;
1010 void OnConnectComplete(const MockConnect& data) override;
1012 private:
1013 DeterministicSocketHelper helper_;
1015 DISALLOW_COPY_AND_ASSIGN(DeterministicMockTCPClientSocket);
1018 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
1019 public:
1020 MockSSLClientSocket(scoped_ptr<ClientSocketHandle> transport_socket,
1021 const HostPortPair& host_and_port,
1022 const SSLConfig& ssl_config,
1023 SSLSocketDataProvider* socket);
1024 ~MockSSLClientSocket() override;
1026 // Socket implementation.
1027 int Read(IOBuffer* buf,
1028 int buf_len,
1029 const CompletionCallback& callback) override;
1030 int Write(IOBuffer* buf,
1031 int buf_len,
1032 const CompletionCallback& callback) override;
1034 // StreamSocket implementation.
1035 int Connect(const CompletionCallback& callback) override;
1036 void Disconnect() override;
1037 bool IsConnected() const override;
1038 bool WasEverUsed() const override;
1039 bool UsingTCPFastOpen() const override;
1040 int GetPeerAddress(IPEndPoint* address) const override;
1041 bool GetSSLInfo(SSLInfo* ssl_info) override;
1043 // SSLClientSocket implementation.
1044 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
1045 NextProtoStatus GetNextProto(std::string* proto) const override;
1047 // This MockSocket does not implement the manual async IO feature.
1048 void OnReadComplete(const MockRead& data) override;
1049 void OnWriteComplete(int rv) override;
1050 void OnConnectComplete(const MockConnect& data) override;
1052 ChannelIDService* GetChannelIDService() const override;
1054 private:
1055 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
1056 const CompletionCallback& callback,
1057 int rv);
1059 scoped_ptr<ClientSocketHandle> transport_;
1060 SSLSocketDataProvider* data_;
1062 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
1065 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
1066 public:
1067 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
1068 ~MockUDPClientSocket() override;
1070 // Socket implementation.
1071 int Read(IOBuffer* buf,
1072 int buf_len,
1073 const CompletionCallback& callback) override;
1074 int Write(IOBuffer* buf,
1075 int buf_len,
1076 const CompletionCallback& callback) override;
1077 int SetReceiveBufferSize(int32 size) override;
1078 int SetSendBufferSize(int32 size) override;
1080 // DatagramSocket implementation.
1081 void Close() override;
1082 int GetPeerAddress(IPEndPoint* address) const override;
1083 int GetLocalAddress(IPEndPoint* address) const override;
1084 const BoundNetLog& NetLog() const override;
1086 // DatagramClientSocket implementation.
1087 int Connect(const IPEndPoint& address) override;
1089 // AsyncSocket implementation.
1090 void OnReadComplete(const MockRead& data) override;
1091 void OnWriteComplete(int rv) override;
1092 void OnConnectComplete(const MockConnect& data) override;
1094 void set_source_port(uint16 port) { source_port_ = port;}
1096 private:
1097 int CompleteRead();
1099 void RunCallbackAsync(const CompletionCallback& callback, int result);
1100 void RunCallback(const CompletionCallback& callback, int result);
1102 bool connected_;
1103 SocketDataProvider* data_;
1104 int read_offset_;
1105 MockRead read_data_;
1106 bool need_read_data_;
1107 uint16 source_port_; // Ephemeral source port.
1109 // Address of the "remote" peer we're connected to.
1110 IPEndPoint peer_addr_;
1112 // While an asynchronous IO is pending, we save our user-buffer state.
1113 scoped_refptr<IOBuffer> pending_read_buf_;
1114 int pending_read_buf_len_;
1115 CompletionCallback pending_read_callback_;
1116 CompletionCallback pending_write_callback_;
1118 BoundNetLog net_log_;
1120 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_;
1122 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket);
1125 class TestSocketRequest : public TestCompletionCallbackBase {
1126 public:
1127 TestSocketRequest(std::vector<TestSocketRequest*>* request_order,
1128 size_t* completion_count);
1129 ~TestSocketRequest() override;
1131 ClientSocketHandle* handle() { return &handle_; }
1133 const CompletionCallback& callback() const { return callback_; }
1135 private:
1136 void OnComplete(int result);
1138 ClientSocketHandle handle_;
1139 std::vector<TestSocketRequest*>* request_order_;
1140 size_t* completion_count_;
1141 CompletionCallback callback_;
1143 DISALLOW_COPY_AND_ASSIGN(TestSocketRequest);
1146 class ClientSocketPoolTest {
1147 public:
1148 enum KeepAlive {
1149 KEEP_ALIVE,
1151 // A socket will be disconnected in addition to handle being reset.
1152 NO_KEEP_ALIVE,
1155 static const int kIndexOutOfBounds;
1156 static const int kRequestNotFound;
1158 ClientSocketPoolTest();
1159 ~ClientSocketPoolTest();
1161 template <typename PoolType>
1162 int StartRequestUsingPool(
1163 PoolType* socket_pool,
1164 const std::string& group_name,
1165 RequestPriority priority,
1166 const scoped_refptr<typename PoolType::SocketParams>& socket_params) {
1167 DCHECK(socket_pool);
1168 TestSocketRequest* request =
1169 new TestSocketRequest(&request_order_, &completion_count_);
1170 requests_.push_back(request);
1171 int rv = request->handle()->Init(group_name,
1172 socket_params,
1173 priority,
1174 request->callback(),
1175 socket_pool,
1176 BoundNetLog());
1177 if (rv != ERR_IO_PENDING)
1178 request_order_.push_back(request);
1179 return rv;
1182 // Provided there were n requests started, takes |index| in range 1..n
1183 // and returns order in which that request completed, in range 1..n,
1184 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound
1185 // if that request did not complete (for example was canceled).
1186 int GetOrderOfRequest(size_t index) const;
1188 // Resets first initialized socket handle from |requests_|. If found such
1189 // a handle, returns true.
1190 bool ReleaseOneConnection(KeepAlive keep_alive);
1192 // Releases connections until there is nothing to release.
1193 void ReleaseAllConnections(KeepAlive keep_alive);
1195 // Note that this uses 0-based indices, while GetOrderOfRequest takes and
1196 // returns 0-based indices.
1197 TestSocketRequest* request(int i) { return requests_[i]; }
1199 size_t requests_size() const { return requests_.size(); }
1200 ScopedVector<TestSocketRequest>* requests() { return &requests_; }
1201 size_t completion_count() const { return completion_count_; }
1203 private:
1204 ScopedVector<TestSocketRequest> requests_;
1205 std::vector<TestSocketRequest*> request_order_;
1206 size_t completion_count_;
1208 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolTest);
1211 class MockTransportSocketParams
1212 : public base::RefCounted<MockTransportSocketParams> {
1213 private:
1214 friend class base::RefCounted<MockTransportSocketParams>;
1215 ~MockTransportSocketParams() {}
1217 DISALLOW_COPY_AND_ASSIGN(MockTransportSocketParams);
1220 class MockTransportClientSocketPool : public TransportClientSocketPool {
1221 public:
1222 typedef MockTransportSocketParams SocketParams;
1224 class MockConnectJob {
1225 public:
1226 MockConnectJob(scoped_ptr<StreamSocket> socket,
1227 ClientSocketHandle* handle,
1228 const CompletionCallback& callback);
1229 ~MockConnectJob();
1231 int Connect();
1232 bool CancelHandle(const ClientSocketHandle* handle);
1234 private:
1235 void OnConnect(int rv);
1237 scoped_ptr<StreamSocket> socket_;
1238 ClientSocketHandle* handle_;
1239 CompletionCallback user_callback_;
1241 DISALLOW_COPY_AND_ASSIGN(MockConnectJob);
1244 MockTransportClientSocketPool(int max_sockets,
1245 int max_sockets_per_group,
1246 ClientSocketFactory* socket_factory);
1248 ~MockTransportClientSocketPool() override;
1250 RequestPriority last_request_priority() const {
1251 return last_request_priority_;
1253 int release_count() const { return release_count_; }
1254 int cancel_count() const { return cancel_count_; }
1256 // TransportClientSocketPool implementation.
1257 int RequestSocket(const std::string& group_name,
1258 const void* socket_params,
1259 RequestPriority priority,
1260 ClientSocketHandle* handle,
1261 const CompletionCallback& callback,
1262 const BoundNetLog& net_log) override;
1264 void CancelRequest(const std::string& group_name,
1265 ClientSocketHandle* handle) override;
1266 void ReleaseSocket(const std::string& group_name,
1267 scoped_ptr<StreamSocket> socket,
1268 int id) override;
1270 private:
1271 ClientSocketFactory* client_socket_factory_;
1272 ScopedVector<MockConnectJob> job_list_;
1273 RequestPriority last_request_priority_;
1274 int release_count_;
1275 int cancel_count_;
1277 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool);
1280 class DeterministicMockClientSocketFactory : public ClientSocketFactory {
1281 public:
1282 DeterministicMockClientSocketFactory();
1283 ~DeterministicMockClientSocketFactory() override;
1285 void AddSocketDataProvider(DeterministicSocketData* socket);
1286 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
1287 void ResetNextMockIndexes();
1289 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory
1290 // created.
1291 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const;
1293 SocketDataProviderArray<DeterministicSocketData>& mock_data() {
1294 return mock_data_;
1296 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() {
1297 return tcp_client_sockets_;
1299 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() {
1300 return udp_client_sockets_;
1303 // ClientSocketFactory
1304 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
1305 DatagramSocket::BindType bind_type,
1306 const RandIntCallback& rand_int_cb,
1307 NetLog* net_log,
1308 const NetLog::Source& source) override;
1309 scoped_ptr<StreamSocket> CreateTransportClientSocket(
1310 const AddressList& addresses,
1311 NetLog* net_log,
1312 const NetLog::Source& source) override;
1313 scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
1314 scoped_ptr<ClientSocketHandle> transport_socket,
1315 const HostPortPair& host_and_port,
1316 const SSLConfig& ssl_config,
1317 const SSLClientSocketContext& context) override;
1318 void ClearSSLSessionCache() override;
1320 private:
1321 SocketDataProviderArray<DeterministicSocketData> mock_data_;
1322 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
1324 // Store pointers to handed out sockets in case the test wants to get them.
1325 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_;
1326 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_;
1327 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
1329 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory);
1332 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
1333 public:
1334 MockSOCKSClientSocketPool(int max_sockets,
1335 int max_sockets_per_group,
1336 TransportClientSocketPool* transport_pool);
1338 ~MockSOCKSClientSocketPool() override;
1340 // SOCKSClientSocketPool implementation.
1341 int RequestSocket(const std::string& group_name,
1342 const void* socket_params,
1343 RequestPriority priority,
1344 ClientSocketHandle* handle,
1345 const CompletionCallback& callback,
1346 const BoundNetLog& net_log) override;
1348 void CancelRequest(const std::string& group_name,
1349 ClientSocketHandle* handle) override;
1350 void ReleaseSocket(const std::string& group_name,
1351 scoped_ptr<StreamSocket> socket,
1352 int id) override;
1354 private:
1355 TransportClientSocketPool* const transport_pool_;
1357 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
1360 // Convenience class to temporarily set the WebSocketEndpointLockManager unlock
1361 // delay to zero for testing purposes. Automatically restores the original value
1362 // when destroyed.
1363 class ScopedWebSocketEndpointZeroUnlockDelay {
1364 public:
1365 ScopedWebSocketEndpointZeroUnlockDelay();
1366 ~ScopedWebSocketEndpointZeroUnlockDelay();
1368 private:
1369 base::TimeDelta old_delay_;
1372 // Constants for a successful SOCKS v5 handshake.
1373 extern const char kSOCKS5GreetRequest[];
1374 extern const int kSOCKS5GreetRequestLength;
1376 extern const char kSOCKS5GreetResponse[];
1377 extern const int kSOCKS5GreetResponseLength;
1379 extern const char kSOCKS5OkRequest[];
1380 extern const int kSOCKS5OkRequestLength;
1382 extern const char kSOCKS5OkResponse[];
1383 extern const int kSOCKS5OkResponseLength;
1385 } // namespace net
1387 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_