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

Side by Side Diff: net/socket/socket_test_util.h

Issue 667923003: Standardize usage of virtual/override/final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/socket_libevent.h ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_
7 7
8 #include <cstring> 8 #include <cstring>
9 #include <deque> 9 #include <deque>
10 #include <string> 10 #include <string>
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 // SocketDataProvider which responds based on static tables of mock reads and 237 // SocketDataProvider which responds based on static tables of mock reads and
238 // writes. 238 // writes.
239 class StaticSocketDataProvider : public SocketDataProvider { 239 class StaticSocketDataProvider : public SocketDataProvider {
240 public: 240 public:
241 StaticSocketDataProvider(); 241 StaticSocketDataProvider();
242 StaticSocketDataProvider(MockRead* reads, 242 StaticSocketDataProvider(MockRead* reads,
243 size_t reads_count, 243 size_t reads_count,
244 MockWrite* writes, 244 MockWrite* writes,
245 size_t writes_count); 245 size_t writes_count);
246 virtual ~StaticSocketDataProvider(); 246 ~StaticSocketDataProvider() override;
247 247
248 // These functions get access to the next available read and write data. 248 // These functions get access to the next available read and write data.
249 const MockRead& PeekRead() const; 249 const MockRead& PeekRead() const;
250 const MockWrite& PeekWrite() const; 250 const MockWrite& PeekWrite() const;
251 // These functions get random access to the read and write data, for timing. 251 // These functions get random access to the read and write data, for timing.
252 const MockRead& PeekRead(size_t index) const; 252 const MockRead& PeekRead(size_t index) const;
253 const MockWrite& PeekWrite(size_t index) const; 253 const MockWrite& PeekWrite(size_t index) const;
254 size_t read_index() const { return read_index_; } 254 size_t read_index() const { return read_index_; }
255 size_t write_index() const { return write_index_; } 255 size_t write_index() const { return write_index_; }
256 size_t read_count() const { return read_count_; } 256 size_t read_count() const { return read_count_; }
257 size_t write_count() const { return write_count_; } 257 size_t write_count() const { return write_count_; }
258 258
259 bool at_read_eof() const { return read_index_ >= read_count_; } 259 bool at_read_eof() const { return read_index_ >= read_count_; }
260 bool at_write_eof() const { return write_index_ >= write_count_; } 260 bool at_write_eof() const { return write_index_ >= write_count_; }
261 261
262 virtual void CompleteRead() {} 262 virtual void CompleteRead() {}
263 263
264 // SocketDataProvider implementation. 264 // SocketDataProvider implementation.
265 virtual MockRead GetNextRead() override; 265 MockRead GetNextRead() override;
266 virtual MockWriteResult OnWrite(const std::string& data) override; 266 MockWriteResult OnWrite(const std::string& data) override;
267 virtual void Reset() override; 267 void Reset() override;
268 268
269 private: 269 private:
270 MockRead* reads_; 270 MockRead* reads_;
271 size_t read_index_; 271 size_t read_index_;
272 size_t read_count_; 272 size_t read_count_;
273 MockWrite* writes_; 273 MockWrite* writes_;
274 size_t write_index_; 274 size_t write_index_;
275 size_t write_count_; 275 size_t write_count_;
276 276
277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); 277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
278 }; 278 };
279 279
280 // SocketDataProvider which can make decisions about next mock reads based on 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 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 282 // example that tested code must send the "Hello!" message before receiving
283 // response. This is useful for testing conversation-like protocols like FTP. 283 // response. This is useful for testing conversation-like protocols like FTP.
284 class DynamicSocketDataProvider : public SocketDataProvider { 284 class DynamicSocketDataProvider : public SocketDataProvider {
285 public: 285 public:
286 DynamicSocketDataProvider(); 286 DynamicSocketDataProvider();
287 virtual ~DynamicSocketDataProvider(); 287 ~DynamicSocketDataProvider() override;
288 288
289 int short_read_limit() const { return short_read_limit_; } 289 int short_read_limit() const { return short_read_limit_; }
290 void set_short_read_limit(int limit) { short_read_limit_ = limit; } 290 void set_short_read_limit(int limit) { short_read_limit_ = limit; }
291 291
292 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; } 292 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; }
293 293
294 // SocketDataProvider implementation. 294 // SocketDataProvider implementation.
295 virtual MockRead GetNextRead() override; 295 MockRead GetNextRead() override;
296 virtual MockWriteResult OnWrite(const std::string& data) = 0; 296 virtual MockWriteResult OnWrite(const std::string& data) = 0;
297 virtual void Reset() override; 297 void Reset() override;
298 298
299 protected: 299 protected:
300 // The next time there is a read from this socket, it will return |data|. 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. 301 // Before calling SimulateRead next time, the previous data must be consumed.
302 void SimulateRead(const char* data, size_t length); 302 void SimulateRead(const char* data, size_t length);
303 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); } 303 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); }
304 304
305 private: 305 private:
306 std::deque<MockRead> reads_; 306 std::deque<MockRead> reads_;
307 307
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // a MockRead to complete. 364 // a MockRead to complete.
365 // |writes| the list of MockWrite completions. 365 // |writes| the list of MockWrite completions.
366 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a 366 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
367 // MockRead(true, 0, 0); 367 // MockRead(true, 0, 0);
368 DelayedSocketData(const MockConnect& connect, 368 DelayedSocketData(const MockConnect& connect,
369 int write_delay, 369 int write_delay,
370 MockRead* reads, 370 MockRead* reads,
371 size_t reads_count, 371 size_t reads_count,
372 MockWrite* writes, 372 MockWrite* writes,
373 size_t writes_count); 373 size_t writes_count);
374 virtual ~DelayedSocketData(); 374 ~DelayedSocketData() override;
375 375
376 void ForceNextRead(); 376 void ForceNextRead();
377 377
378 // StaticSocketDataProvider: 378 // StaticSocketDataProvider:
379 virtual MockRead GetNextRead() override; 379 MockRead GetNextRead() override;
380 virtual MockWriteResult OnWrite(const std::string& data) override; 380 MockWriteResult OnWrite(const std::string& data) override;
381 virtual void Reset() override; 381 void Reset() override;
382 virtual void CompleteRead() override; 382 void CompleteRead() override;
383 383
384 private: 384 private:
385 int write_delay_; 385 int write_delay_;
386 bool read_in_progress_; 386 bool read_in_progress_;
387 387
388 base::WeakPtrFactory<DelayedSocketData> weak_factory_; 388 base::WeakPtrFactory<DelayedSocketData> weak_factory_;
389 389
390 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData); 390 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData);
391 }; 391 };
392 392
(...skipping 12 matching lines...) Expand all
405 public: 405 public:
406 // |reads| the list of MockRead completions. 406 // |reads| the list of MockRead completions.
407 // |writes| the list of MockWrite completions. 407 // |writes| the list of MockWrite completions.
408 // Note: All MockReads and MockWrites must be async. 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 409 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
410 // MockRead(true, 0, 0); 410 // MockRead(true, 0, 0);
411 OrderedSocketData(MockRead* reads, 411 OrderedSocketData(MockRead* reads,
412 size_t reads_count, 412 size_t reads_count,
413 MockWrite* writes, 413 MockWrite* writes,
414 size_t writes_count); 414 size_t writes_count);
415 virtual ~OrderedSocketData(); 415 ~OrderedSocketData() override;
416 416
417 // |connect| the result for the connect phase. 417 // |connect| the result for the connect phase.
418 // |reads| the list of MockRead completions. 418 // |reads| the list of MockRead completions.
419 // |writes| the list of MockWrite completions. 419 // |writes| the list of MockWrite completions.
420 // Note: All MockReads and MockWrites must be async. 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 421 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a
422 // MockRead(true, 0, 0); 422 // MockRead(true, 0, 0);
423 OrderedSocketData(const MockConnect& connect, 423 OrderedSocketData(const MockConnect& connect,
424 MockRead* reads, 424 MockRead* reads,
425 size_t reads_count, 425 size_t reads_count,
426 MockWrite* writes, 426 MockWrite* writes,
427 size_t writes_count); 427 size_t writes_count);
428 428
429 // Posts a quit message to the current message loop, if one is running. 429 // Posts a quit message to the current message loop, if one is running.
430 void EndLoop(); 430 void EndLoop();
431 431
432 // StaticSocketDataProvider: 432 // StaticSocketDataProvider:
433 virtual MockRead GetNextRead() override; 433 MockRead GetNextRead() override;
434 virtual MockWriteResult OnWrite(const std::string& data) override; 434 MockWriteResult OnWrite(const std::string& data) override;
435 virtual void Reset() override; 435 void Reset() override;
436 virtual void CompleteRead() override; 436 void CompleteRead() override;
437 437
438 private: 438 private:
439 int sequence_number_; 439 int sequence_number_;
440 int loop_stop_stage_; 440 int loop_stop_stage_;
441 bool blocked_; 441 bool blocked_;
442 442
443 base::WeakPtrFactory<OrderedSocketData> weak_factory_; 443 base::WeakPtrFactory<OrderedSocketData> weak_factory_;
444 444
445 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData); 445 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData);
446 }; 446 };
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 protected: 529 protected:
530 virtual ~Delegate() {} 530 virtual ~Delegate() {}
531 }; 531 };
532 532
533 // |reads| the list of MockRead completions. 533 // |reads| the list of MockRead completions.
534 // |writes| the list of MockWrite completions. 534 // |writes| the list of MockWrite completions.
535 DeterministicSocketData(MockRead* reads, 535 DeterministicSocketData(MockRead* reads,
536 size_t reads_count, 536 size_t reads_count,
537 MockWrite* writes, 537 MockWrite* writes,
538 size_t writes_count); 538 size_t writes_count);
539 virtual ~DeterministicSocketData(); 539 ~DeterministicSocketData() override;
540 540
541 // Consume all the data up to the give stop point (via SetStop()). 541 // Consume all the data up to the give stop point (via SetStop()).
542 void Run(); 542 void Run();
543 543
544 // Set the stop point to be |steps| from now, and then invoke Run(). 544 // Set the stop point to be |steps| from now, and then invoke Run().
545 void RunFor(int steps); 545 void RunFor(int steps);
546 546
547 // Stop at step |seq|, which must be in the future. 547 // Stop at step |seq|, which must be in the future.
548 virtual void SetStop(int seq); 548 virtual void SetStop(int seq);
549 549
550 // Stop |seq| steps after the current step. 550 // Stop |seq| steps after the current step.
551 virtual void StopAfter(int seq); 551 virtual void StopAfter(int seq);
552 bool stopped() const { return stopped_; } 552 bool stopped() const { return stopped_; }
553 void SetStopped(bool val) { stopped_ = val; } 553 void SetStopped(bool val) { stopped_ = val; }
554 MockRead& current_read() { return current_read_; } 554 MockRead& current_read() { return current_read_; }
555 MockWrite& current_write() { return current_write_; } 555 MockWrite& current_write() { return current_write_; }
556 int sequence_number() const { return sequence_number_; } 556 int sequence_number() const { return sequence_number_; }
557 void set_delegate(base::WeakPtr<Delegate> delegate) { delegate_ = delegate; } 557 void set_delegate(base::WeakPtr<Delegate> delegate) { delegate_ = delegate; }
558 558
559 // StaticSocketDataProvider: 559 // StaticSocketDataProvider:
560 560
561 // When the socket calls Read(), that calls GetNextRead(), and expects either 561 // When the socket calls Read(), that calls GetNextRead(), and expects either
562 // ERR_IO_PENDING or data. 562 // ERR_IO_PENDING or data.
563 virtual MockRead GetNextRead() override; 563 MockRead GetNextRead() override;
564 564
565 // When the socket calls Write(), it always completes synchronously. OnWrite() 565 // When the socket calls Write(), it always completes synchronously. OnWrite()
566 // checks to make sure the written data matches the expected data. The 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. 567 // callback will not be invoked until its sequence number is reached.
568 virtual MockWriteResult OnWrite(const std::string& data) override; 568 MockWriteResult OnWrite(const std::string& data) override;
569 virtual void Reset() override; 569 void Reset() override;
570 virtual void CompleteRead() override {} 570 void CompleteRead() override {}
571 571
572 private: 572 private:
573 // Invoke the read and write callbacks, if the timing is appropriate. 573 // Invoke the read and write callbacks, if the timing is appropriate.
574 void InvokeCallbacks(); 574 void InvokeCallbacks();
575 575
576 void NextStep(); 576 void NextStep();
577 577
578 void VerifyCorrectSequenceNumbers(MockRead* reads, 578 void VerifyCorrectSequenceNumbers(MockRead* reads,
579 size_t reads_count, 579 size_t reads_count,
580 MockWrite* writes, 580 MockWrite* writes,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 class MockSSLClientSocket; 626 class MockSSLClientSocket;
627 627
628 // ClientSocketFactory which contains arrays of sockets of each type. 628 // ClientSocketFactory which contains arrays of sockets of each type.
629 // You should first fill the arrays using AddMock{SSL,}Socket. When the factory 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. 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 631 // You can use ResetNextMockIndexes to reset that next entry index for all mock
632 // socket types. 632 // socket types.
633 class MockClientSocketFactory : public ClientSocketFactory { 633 class MockClientSocketFactory : public ClientSocketFactory {
634 public: 634 public:
635 MockClientSocketFactory(); 635 MockClientSocketFactory();
636 virtual ~MockClientSocketFactory(); 636 ~MockClientSocketFactory() override;
637 637
638 void AddSocketDataProvider(SocketDataProvider* socket); 638 void AddSocketDataProvider(SocketDataProvider* socket);
639 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); 639 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
640 void ResetNextMockIndexes(); 640 void ResetNextMockIndexes();
641 641
642 SocketDataProviderArray<SocketDataProvider>& mock_data() { 642 SocketDataProviderArray<SocketDataProvider>& mock_data() {
643 return mock_data_; 643 return mock_data_;
644 } 644 }
645 645
646 // Note: this method is unsafe; the elements of the returned vector 646 // Note: this method is unsafe; the elements of the returned vector
647 // are not necessarily valid. 647 // are not necessarily valid.
648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const { 648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const {
649 return ssl_client_sockets_; 649 return ssl_client_sockets_;
650 } 650 }
651 651
652 // ClientSocketFactory 652 // ClientSocketFactory
653 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 653 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
654 DatagramSocket::BindType bind_type, 654 DatagramSocket::BindType bind_type,
655 const RandIntCallback& rand_int_cb, 655 const RandIntCallback& rand_int_cb,
656 NetLog* net_log, 656 NetLog* net_log,
657 const NetLog::Source& source) override; 657 const NetLog::Source& source) override;
658 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 658 scoped_ptr<StreamSocket> CreateTransportClientSocket(
659 const AddressList& addresses, 659 const AddressList& addresses,
660 NetLog* net_log, 660 NetLog* net_log,
661 const NetLog::Source& source) override; 661 const NetLog::Source& source) override;
662 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 662 scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
663 scoped_ptr<ClientSocketHandle> transport_socket, 663 scoped_ptr<ClientSocketHandle> transport_socket,
664 const HostPortPair& host_and_port, 664 const HostPortPair& host_and_port,
665 const SSLConfig& ssl_config, 665 const SSLConfig& ssl_config,
666 const SSLClientSocketContext& context) override; 666 const SSLClientSocketContext& context) override;
667 virtual void ClearSSLSessionCache() override; 667 void ClearSSLSessionCache() override;
668 668
669 private: 669 private:
670 SocketDataProviderArray<SocketDataProvider> mock_data_; 670 SocketDataProviderArray<SocketDataProvider> mock_data_;
671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
672 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 672 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
673 }; 673 };
674 674
675 class MockClientSocket : public SSLClientSocket { 675 class MockClientSocket : public SSLClientSocket {
676 public: 676 public:
677 // Value returned by GetTLSUniqueChannelBinding(). 677 // Value returned by GetTLSUniqueChannelBinding().
678 static const char kTlsUnique[]; 678 static const char kTlsUnique[];
679 679
680 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as 680 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
681 // unique socket IDs. 681 // unique socket IDs.
682 explicit MockClientSocket(const BoundNetLog& net_log); 682 explicit MockClientSocket(const BoundNetLog& net_log);
683 683
684 // Socket implementation. 684 // Socket implementation.
685 virtual int Read(IOBuffer* buf, 685 virtual int Read(IOBuffer* buf,
686 int buf_len, 686 int buf_len,
687 const CompletionCallback& callback) = 0; 687 const CompletionCallback& callback) = 0;
688 virtual int Write(IOBuffer* buf, 688 virtual int Write(IOBuffer* buf,
689 int buf_len, 689 int buf_len,
690 const CompletionCallback& callback) = 0; 690 const CompletionCallback& callback) = 0;
691 virtual int SetReceiveBufferSize(int32 size) override; 691 int SetReceiveBufferSize(int32 size) override;
692 virtual int SetSendBufferSize(int32 size) override; 692 int SetSendBufferSize(int32 size) override;
693 693
694 // StreamSocket implementation. 694 // StreamSocket implementation.
695 virtual int Connect(const CompletionCallback& callback) = 0; 695 virtual int Connect(const CompletionCallback& callback) = 0;
696 virtual void Disconnect() override; 696 void Disconnect() override;
697 virtual bool IsConnected() const override; 697 bool IsConnected() const override;
698 virtual bool IsConnectedAndIdle() const override; 698 bool IsConnectedAndIdle() const override;
699 virtual int GetPeerAddress(IPEndPoint* address) const override; 699 int GetPeerAddress(IPEndPoint* address) const override;
700 virtual int GetLocalAddress(IPEndPoint* address) const override; 700 int GetLocalAddress(IPEndPoint* address) const override;
701 virtual const BoundNetLog& NetLog() const override; 701 const BoundNetLog& NetLog() const override;
702 virtual void SetSubresourceSpeculation() override {} 702 void SetSubresourceSpeculation() override {}
703 virtual void SetOmniboxSpeculation() override {} 703 void SetOmniboxSpeculation() override {}
704 704
705 // SSLClientSocket implementation. 705 // SSLClientSocket implementation.
706 virtual std::string GetSessionCacheKey() const override; 706 std::string GetSessionCacheKey() const override;
707 virtual bool InSessionCache() const override; 707 bool InSessionCache() const override;
708 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) override; 708 void SetHandshakeCompletionCallback(const base::Closure& cb) override;
709 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 709 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
710 override; 710 int ExportKeyingMaterial(const base::StringPiece& label,
711 virtual int ExportKeyingMaterial(const base::StringPiece& label, 711 bool has_context,
712 bool has_context, 712 const base::StringPiece& context,
713 const base::StringPiece& context, 713 unsigned char* out,
714 unsigned char* out, 714 unsigned int outlen) override;
715 unsigned int outlen) override; 715 int GetTLSUniqueChannelBinding(std::string* out) override;
716 virtual int GetTLSUniqueChannelBinding(std::string* out) override; 716 NextProtoStatus GetNextProto(std::string* proto) override;
717 virtual NextProtoStatus GetNextProto(std::string* proto) override; 717 ChannelIDService* GetChannelIDService() const override;
718 virtual ChannelIDService* GetChannelIDService() const override;
719 718
720 protected: 719 protected:
721 virtual ~MockClientSocket(); 720 ~MockClientSocket() override;
722 void RunCallbackAsync(const CompletionCallback& callback, int result); 721 void RunCallbackAsync(const CompletionCallback& callback, int result);
723 void RunCallback(const CompletionCallback& callback, int result); 722 void RunCallback(const CompletionCallback& callback, int result);
724 723
725 // SSLClientSocket implementation. 724 // SSLClientSocket implementation.
726 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() 725 scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
727 const override; 726 const override;
728 727
729 // True if Connect completed successfully and Disconnect hasn't been called. 728 // True if Connect completed successfully and Disconnect hasn't been called.
730 bool connected_; 729 bool connected_;
731 730
732 // Address of the "remote" peer we're connected to. 731 // Address of the "remote" peer we're connected to.
733 IPEndPoint peer_addr_; 732 IPEndPoint peer_addr_;
734 733
735 BoundNetLog net_log_; 734 BoundNetLog net_log_;
736 735
737 private: 736 private:
738 base::WeakPtrFactory<MockClientSocket> weak_factory_; 737 base::WeakPtrFactory<MockClientSocket> weak_factory_;
739 738
740 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); 739 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
741 }; 740 };
742 741
743 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { 742 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
744 public: 743 public:
745 MockTCPClientSocket(const AddressList& addresses, 744 MockTCPClientSocket(const AddressList& addresses,
746 net::NetLog* net_log, 745 net::NetLog* net_log,
747 SocketDataProvider* socket); 746 SocketDataProvider* socket);
748 virtual ~MockTCPClientSocket(); 747 ~MockTCPClientSocket() override;
749 748
750 const AddressList& addresses() const { return addresses_; } 749 const AddressList& addresses() const { return addresses_; }
751 750
752 // Socket implementation. 751 // Socket implementation.
753 virtual int Read(IOBuffer* buf, 752 int Read(IOBuffer* buf,
754 int buf_len, 753 int buf_len,
755 const CompletionCallback& callback) override; 754 const CompletionCallback& callback) override;
756 virtual int Write(IOBuffer* buf, 755 int Write(IOBuffer* buf,
757 int buf_len, 756 int buf_len,
758 const CompletionCallback& callback) override; 757 const CompletionCallback& callback) override;
759 758
760 // StreamSocket implementation. 759 // StreamSocket implementation.
761 virtual int Connect(const CompletionCallback& callback) override; 760 int Connect(const CompletionCallback& callback) override;
762 virtual void Disconnect() override; 761 void Disconnect() override;
763 virtual bool IsConnected() const override; 762 bool IsConnected() const override;
764 virtual bool IsConnectedAndIdle() const override; 763 bool IsConnectedAndIdle() const override;
765 virtual int GetPeerAddress(IPEndPoint* address) const override; 764 int GetPeerAddress(IPEndPoint* address) const override;
766 virtual bool WasEverUsed() const override; 765 bool WasEverUsed() const override;
767 virtual bool UsingTCPFastOpen() const override; 766 bool UsingTCPFastOpen() const override;
768 virtual bool WasNpnNegotiated() const override; 767 bool WasNpnNegotiated() const override;
769 virtual bool GetSSLInfo(SSLInfo* ssl_info) override; 768 bool GetSSLInfo(SSLInfo* ssl_info) override;
770 769
771 // AsyncSocket: 770 // AsyncSocket:
772 virtual void OnReadComplete(const MockRead& data) override; 771 void OnReadComplete(const MockRead& data) override;
773 virtual void OnConnectComplete(const MockConnect& data) override; 772 void OnConnectComplete(const MockConnect& data) override;
774 773
775 private: 774 private:
776 int CompleteRead(); 775 int CompleteRead();
777 776
778 AddressList addresses_; 777 AddressList addresses_;
779 778
780 SocketDataProvider* data_; 779 SocketDataProvider* data_;
781 int read_offset_; 780 int read_offset_;
782 MockRead read_data_; 781 MockRead read_data_;
783 bool need_read_data_; 782 bool need_read_data_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 843
845 // Mock UDP socket to be used in conjunction with DeterministicSocketData. 844 // Mock UDP socket to be used in conjunction with DeterministicSocketData.
846 class DeterministicMockUDPClientSocket 845 class DeterministicMockUDPClientSocket
847 : public DatagramClientSocket, 846 : public DatagramClientSocket,
848 public AsyncSocket, 847 public AsyncSocket,
849 public DeterministicSocketData::Delegate, 848 public DeterministicSocketData::Delegate,
850 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> { 849 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> {
851 public: 850 public:
852 DeterministicMockUDPClientSocket(net::NetLog* net_log, 851 DeterministicMockUDPClientSocket(net::NetLog* net_log,
853 DeterministicSocketData* data); 852 DeterministicSocketData* data);
854 virtual ~DeterministicMockUDPClientSocket(); 853 ~DeterministicMockUDPClientSocket() override;
855 854
856 // DeterministicSocketData::Delegate: 855 // DeterministicSocketData::Delegate:
857 virtual bool WritePending() const override; 856 bool WritePending() const override;
858 virtual bool ReadPending() const override; 857 bool ReadPending() const override;
859 virtual void CompleteWrite() override; 858 void CompleteWrite() override;
860 virtual int CompleteRead() override; 859 int CompleteRead() override;
861 860
862 // Socket implementation. 861 // Socket implementation.
863 virtual int Read(IOBuffer* buf, 862 int Read(IOBuffer* buf,
864 int buf_len, 863 int buf_len,
865 const CompletionCallback& callback) override; 864 const CompletionCallback& callback) override;
866 virtual int Write(IOBuffer* buf, 865 int Write(IOBuffer* buf,
867 int buf_len, 866 int buf_len,
868 const CompletionCallback& callback) override; 867 const CompletionCallback& callback) override;
869 virtual int SetReceiveBufferSize(int32 size) override; 868 int SetReceiveBufferSize(int32 size) override;
870 virtual int SetSendBufferSize(int32 size) override; 869 int SetSendBufferSize(int32 size) override;
871 870
872 // DatagramSocket implementation. 871 // DatagramSocket implementation.
873 virtual void Close() override; 872 void Close() override;
874 virtual int GetPeerAddress(IPEndPoint* address) const override; 873 int GetPeerAddress(IPEndPoint* address) const override;
875 virtual int GetLocalAddress(IPEndPoint* address) const override; 874 int GetLocalAddress(IPEndPoint* address) const override;
876 virtual const BoundNetLog& NetLog() const override; 875 const BoundNetLog& NetLog() const override;
877 876
878 // DatagramClientSocket implementation. 877 // DatagramClientSocket implementation.
879 virtual int Connect(const IPEndPoint& address) override; 878 int Connect(const IPEndPoint& address) override;
880 879
881 // AsyncSocket implementation. 880 // AsyncSocket implementation.
882 virtual void OnReadComplete(const MockRead& data) override; 881 void OnReadComplete(const MockRead& data) override;
883 virtual void OnConnectComplete(const MockConnect& data) override; 882 void OnConnectComplete(const MockConnect& data) override;
884 883
885 void set_source_port(int port) { source_port_ = port; } 884 void set_source_port(int port) { source_port_ = port; }
886 885
887 private: 886 private:
888 bool connected_; 887 bool connected_;
889 IPEndPoint peer_address_; 888 IPEndPoint peer_address_;
890 DeterministicSocketHelper helper_; 889 DeterministicSocketHelper helper_;
891 int source_port_; // Ephemeral source port. 890 int source_port_; // Ephemeral source port.
892 891
893 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket); 892 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket);
894 }; 893 };
895 894
896 // Mock TCP socket to be used in conjunction with DeterministicSocketData. 895 // Mock TCP socket to be used in conjunction with DeterministicSocketData.
897 class DeterministicMockTCPClientSocket 896 class DeterministicMockTCPClientSocket
898 : public MockClientSocket, 897 : public MockClientSocket,
899 public AsyncSocket, 898 public AsyncSocket,
900 public DeterministicSocketData::Delegate, 899 public DeterministicSocketData::Delegate,
901 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { 900 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> {
902 public: 901 public:
903 DeterministicMockTCPClientSocket(net::NetLog* net_log, 902 DeterministicMockTCPClientSocket(net::NetLog* net_log,
904 DeterministicSocketData* data); 903 DeterministicSocketData* data);
905 virtual ~DeterministicMockTCPClientSocket(); 904 ~DeterministicMockTCPClientSocket() override;
906 905
907 // DeterministicSocketData::Delegate: 906 // DeterministicSocketData::Delegate:
908 virtual bool WritePending() const override; 907 bool WritePending() const override;
909 virtual bool ReadPending() const override; 908 bool ReadPending() const override;
910 virtual void CompleteWrite() override; 909 void CompleteWrite() override;
911 virtual int CompleteRead() override; 910 int CompleteRead() override;
912 911
913 // Socket: 912 // Socket:
914 virtual int Write(IOBuffer* buf, 913 int Write(IOBuffer* buf,
915 int buf_len, 914 int buf_len,
916 const CompletionCallback& callback) override; 915 const CompletionCallback& callback) override;
917 virtual int Read(IOBuffer* buf, 916 int Read(IOBuffer* buf,
918 int buf_len, 917 int buf_len,
919 const CompletionCallback& callback) override; 918 const CompletionCallback& callback) override;
920 919
921 // StreamSocket: 920 // StreamSocket:
922 virtual int Connect(const CompletionCallback& callback) override; 921 int Connect(const CompletionCallback& callback) override;
923 virtual void Disconnect() override; 922 void Disconnect() override;
924 virtual bool IsConnected() const override; 923 bool IsConnected() const override;
925 virtual bool IsConnectedAndIdle() const override; 924 bool IsConnectedAndIdle() const override;
926 virtual bool WasEverUsed() const override; 925 bool WasEverUsed() const override;
927 virtual bool UsingTCPFastOpen() const override; 926 bool UsingTCPFastOpen() const override;
928 virtual bool WasNpnNegotiated() const override; 927 bool WasNpnNegotiated() const override;
929 virtual bool GetSSLInfo(SSLInfo* ssl_info) override; 928 bool GetSSLInfo(SSLInfo* ssl_info) override;
930 929
931 // AsyncSocket: 930 // AsyncSocket:
932 virtual void OnReadComplete(const MockRead& data) override; 931 void OnReadComplete(const MockRead& data) override;
933 virtual void OnConnectComplete(const MockConnect& data) override; 932 void OnConnectComplete(const MockConnect& data) override;
934 933
935 private: 934 private:
936 DeterministicSocketHelper helper_; 935 DeterministicSocketHelper helper_;
937 936
938 DISALLOW_COPY_AND_ASSIGN(DeterministicMockTCPClientSocket); 937 DISALLOW_COPY_AND_ASSIGN(DeterministicMockTCPClientSocket);
939 }; 938 };
940 939
941 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { 940 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
942 public: 941 public:
943 MockSSLClientSocket(scoped_ptr<ClientSocketHandle> transport_socket, 942 MockSSLClientSocket(scoped_ptr<ClientSocketHandle> transport_socket,
944 const HostPortPair& host_and_port, 943 const HostPortPair& host_and_port,
945 const SSLConfig& ssl_config, 944 const SSLConfig& ssl_config,
946 SSLSocketDataProvider* socket); 945 SSLSocketDataProvider* socket);
947 virtual ~MockSSLClientSocket(); 946 ~MockSSLClientSocket() override;
948 947
949 // Socket implementation. 948 // Socket implementation.
950 virtual int Read(IOBuffer* buf, 949 int Read(IOBuffer* buf,
951 int buf_len, 950 int buf_len,
952 const CompletionCallback& callback) override; 951 const CompletionCallback& callback) override;
953 virtual int Write(IOBuffer* buf, 952 int Write(IOBuffer* buf,
954 int buf_len, 953 int buf_len,
955 const CompletionCallback& callback) override; 954 const CompletionCallback& callback) override;
956 955
957 // StreamSocket implementation. 956 // StreamSocket implementation.
958 virtual int Connect(const CompletionCallback& callback) override; 957 int Connect(const CompletionCallback& callback) override;
959 virtual void Disconnect() override; 958 void Disconnect() override;
960 virtual bool IsConnected() const override; 959 bool IsConnected() const override;
961 virtual bool WasEverUsed() const override; 960 bool WasEverUsed() const override;
962 virtual bool UsingTCPFastOpen() const override; 961 bool UsingTCPFastOpen() const override;
963 virtual int GetPeerAddress(IPEndPoint* address) const override; 962 int GetPeerAddress(IPEndPoint* address) const override;
964 virtual bool WasNpnNegotiated() const override; 963 bool WasNpnNegotiated() const override;
965 virtual bool GetSSLInfo(SSLInfo* ssl_info) override; 964 bool GetSSLInfo(SSLInfo* ssl_info) override;
966 965
967 // SSLClientSocket implementation. 966 // SSLClientSocket implementation.
968 virtual std::string GetSessionCacheKey() const override; 967 std::string GetSessionCacheKey() const override;
969 virtual bool InSessionCache() const override; 968 bool InSessionCache() const override;
970 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) override; 969 void SetHandshakeCompletionCallback(const base::Closure& cb) override;
971 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 970 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
972 override; 971 NextProtoStatus GetNextProto(std::string* proto) override;
973 virtual NextProtoStatus GetNextProto(std::string* proto) override; 972 bool set_was_npn_negotiated(bool negotiated) override;
974 virtual bool set_was_npn_negotiated(bool negotiated) override; 973 void set_protocol_negotiated(NextProto protocol_negotiated) override;
975 virtual void set_protocol_negotiated(NextProto protocol_negotiated) override; 974 NextProto GetNegotiatedProtocol() const override;
976 virtual NextProto GetNegotiatedProtocol() const override;
977 975
978 // This MockSocket does not implement the manual async IO feature. 976 // This MockSocket does not implement the manual async IO feature.
979 virtual void OnReadComplete(const MockRead& data) override; 977 void OnReadComplete(const MockRead& data) override;
980 virtual void OnConnectComplete(const MockConnect& data) override; 978 void OnConnectComplete(const MockConnect& data) override;
981 979
982 virtual bool WasChannelIDSent() const override; 980 bool WasChannelIDSent() const override;
983 virtual void set_channel_id_sent(bool channel_id_sent) override; 981 void set_channel_id_sent(bool channel_id_sent) override;
984 virtual ChannelIDService* GetChannelIDService() const override; 982 ChannelIDService* GetChannelIDService() const override;
985 983
986 bool reached_connect() const { return reached_connect_; } 984 bool reached_connect() const { return reached_connect_; }
987 985
988 // Resumes the connection of a socket that was paused for testing. 986 // Resumes the connection of a socket that was paused for testing.
989 // |connect_callback_| should be set before invoking this method. 987 // |connect_callback_| should be set before invoking this method.
990 void RestartPausedConnect(); 988 void RestartPausedConnect();
991 989
992 private: 990 private:
993 enum ConnectState { 991 enum ConnectState {
994 STATE_NONE, 992 STATE_NONE,
(...skipping 26 matching lines...) Expand all
1021 base::Closure handshake_completion_callback_; 1019 base::Closure handshake_completion_callback_;
1022 1020
1023 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_; 1021 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_;
1024 1022
1025 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 1023 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
1026 }; 1024 };
1027 1025
1028 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1026 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
1029 public: 1027 public:
1030 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1028 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
1031 virtual ~MockUDPClientSocket(); 1029 ~MockUDPClientSocket() override;
1032 1030
1033 // Socket implementation. 1031 // Socket implementation.
1034 virtual int Read(IOBuffer* buf, 1032 int Read(IOBuffer* buf,
1035 int buf_len, 1033 int buf_len,
1036 const CompletionCallback& callback) override; 1034 const CompletionCallback& callback) override;
1037 virtual int Write(IOBuffer* buf, 1035 int Write(IOBuffer* buf,
1038 int buf_len, 1036 int buf_len,
1039 const CompletionCallback& callback) override; 1037 const CompletionCallback& callback) override;
1040 virtual int SetReceiveBufferSize(int32 size) override; 1038 int SetReceiveBufferSize(int32 size) override;
1041 virtual int SetSendBufferSize(int32 size) override; 1039 int SetSendBufferSize(int32 size) override;
1042 1040
1043 // DatagramSocket implementation. 1041 // DatagramSocket implementation.
1044 virtual void Close() override; 1042 void Close() override;
1045 virtual int GetPeerAddress(IPEndPoint* address) const override; 1043 int GetPeerAddress(IPEndPoint* address) const override;
1046 virtual int GetLocalAddress(IPEndPoint* address) const override; 1044 int GetLocalAddress(IPEndPoint* address) const override;
1047 virtual const BoundNetLog& NetLog() const override; 1045 const BoundNetLog& NetLog() const override;
1048 1046
1049 // DatagramClientSocket implementation. 1047 // DatagramClientSocket implementation.
1050 virtual int Connect(const IPEndPoint& address) override; 1048 int Connect(const IPEndPoint& address) override;
1051 1049
1052 // AsyncSocket implementation. 1050 // AsyncSocket implementation.
1053 virtual void OnReadComplete(const MockRead& data) override; 1051 void OnReadComplete(const MockRead& data) override;
1054 virtual void OnConnectComplete(const MockConnect& data) override; 1052 void OnConnectComplete(const MockConnect& data) override;
1055 1053
1056 void set_source_port(int port) { source_port_ = port;} 1054 void set_source_port(int port) { source_port_ = port;}
1057 1055
1058 private: 1056 private:
1059 int CompleteRead(); 1057 int CompleteRead();
1060 1058
1061 void RunCallbackAsync(const CompletionCallback& callback, int result); 1059 void RunCallbackAsync(const CompletionCallback& callback, int result);
1062 void RunCallback(const CompletionCallback& callback, int result); 1060 void RunCallback(const CompletionCallback& callback, int result);
1063 1061
1064 bool connected_; 1062 bool connected_;
(...skipping 15 matching lines...) Expand all
1080 1078
1081 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; 1079 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_;
1082 1080
1083 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); 1081 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket);
1084 }; 1082 };
1085 1083
1086 class TestSocketRequest : public TestCompletionCallbackBase { 1084 class TestSocketRequest : public TestCompletionCallbackBase {
1087 public: 1085 public:
1088 TestSocketRequest(std::vector<TestSocketRequest*>* request_order, 1086 TestSocketRequest(std::vector<TestSocketRequest*>* request_order,
1089 size_t* completion_count); 1087 size_t* completion_count);
1090 virtual ~TestSocketRequest(); 1088 ~TestSocketRequest() override;
1091 1089
1092 ClientSocketHandle* handle() { return &handle_; } 1090 ClientSocketHandle* handle() { return &handle_; }
1093 1091
1094 const net::CompletionCallback& callback() const { return callback_; } 1092 const net::CompletionCallback& callback() const { return callback_; }
1095 1093
1096 private: 1094 private:
1097 void OnComplete(int result); 1095 void OnComplete(int result);
1098 1096
1099 ClientSocketHandle handle_; 1097 ClientSocketHandle handle_;
1100 std::vector<TestSocketRequest*>* request_order_; 1098 std::vector<TestSocketRequest*>* request_order_;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 CompletionCallback user_callback_; 1198 CompletionCallback user_callback_;
1201 1199
1202 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); 1200 DISALLOW_COPY_AND_ASSIGN(MockConnectJob);
1203 }; 1201 };
1204 1202
1205 MockTransportClientSocketPool(int max_sockets, 1203 MockTransportClientSocketPool(int max_sockets,
1206 int max_sockets_per_group, 1204 int max_sockets_per_group,
1207 ClientSocketPoolHistograms* histograms, 1205 ClientSocketPoolHistograms* histograms,
1208 ClientSocketFactory* socket_factory); 1206 ClientSocketFactory* socket_factory);
1209 1207
1210 virtual ~MockTransportClientSocketPool(); 1208 ~MockTransportClientSocketPool() override;
1211 1209
1212 RequestPriority last_request_priority() const { 1210 RequestPriority last_request_priority() const {
1213 return last_request_priority_; 1211 return last_request_priority_;
1214 } 1212 }
1215 int release_count() const { return release_count_; } 1213 int release_count() const { return release_count_; }
1216 int cancel_count() const { return cancel_count_; } 1214 int cancel_count() const { return cancel_count_; }
1217 1215
1218 // TransportClientSocketPool implementation. 1216 // TransportClientSocketPool implementation.
1219 virtual int RequestSocket(const std::string& group_name, 1217 int RequestSocket(const std::string& group_name,
1220 const void* socket_params, 1218 const void* socket_params,
1221 RequestPriority priority, 1219 RequestPriority priority,
1222 ClientSocketHandle* handle, 1220 ClientSocketHandle* handle,
1223 const CompletionCallback& callback, 1221 const CompletionCallback& callback,
1224 const BoundNetLog& net_log) override; 1222 const BoundNetLog& net_log) override;
1225 1223
1226 virtual void CancelRequest(const std::string& group_name, 1224 void CancelRequest(const std::string& group_name,
1227 ClientSocketHandle* handle) override; 1225 ClientSocketHandle* handle) override;
1228 virtual void ReleaseSocket(const std::string& group_name, 1226 void ReleaseSocket(const std::string& group_name,
1229 scoped_ptr<StreamSocket> socket, 1227 scoped_ptr<StreamSocket> socket,
1230 int id) override; 1228 int id) override;
1231 1229
1232 private: 1230 private:
1233 ClientSocketFactory* client_socket_factory_; 1231 ClientSocketFactory* client_socket_factory_;
1234 ScopedVector<MockConnectJob> job_list_; 1232 ScopedVector<MockConnectJob> job_list_;
1235 RequestPriority last_request_priority_; 1233 RequestPriority last_request_priority_;
1236 int release_count_; 1234 int release_count_;
1237 int cancel_count_; 1235 int cancel_count_;
1238 1236
1239 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); 1237 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool);
1240 }; 1238 };
1241 1239
1242 class DeterministicMockClientSocketFactory : public ClientSocketFactory { 1240 class DeterministicMockClientSocketFactory : public ClientSocketFactory {
1243 public: 1241 public:
1244 DeterministicMockClientSocketFactory(); 1242 DeterministicMockClientSocketFactory();
1245 virtual ~DeterministicMockClientSocketFactory(); 1243 ~DeterministicMockClientSocketFactory() override;
1246 1244
1247 void AddSocketDataProvider(DeterministicSocketData* socket); 1245 void AddSocketDataProvider(DeterministicSocketData* socket);
1248 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); 1246 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
1249 void ResetNextMockIndexes(); 1247 void ResetNextMockIndexes();
1250 1248
1251 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory 1249 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory
1252 // created. 1250 // created.
1253 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; 1251 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const;
1254 1252
1255 SocketDataProviderArray<DeterministicSocketData>& mock_data() { 1253 SocketDataProviderArray<DeterministicSocketData>& mock_data() {
1256 return mock_data_; 1254 return mock_data_;
1257 } 1255 }
1258 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() { 1256 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() {
1259 return tcp_client_sockets_; 1257 return tcp_client_sockets_;
1260 } 1258 }
1261 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() { 1259 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() {
1262 return udp_client_sockets_; 1260 return udp_client_sockets_;
1263 } 1261 }
1264 1262
1265 // ClientSocketFactory 1263 // ClientSocketFactory
1266 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 1264 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
1267 DatagramSocket::BindType bind_type, 1265 DatagramSocket::BindType bind_type,
1268 const RandIntCallback& rand_int_cb, 1266 const RandIntCallback& rand_int_cb,
1269 NetLog* net_log, 1267 NetLog* net_log,
1270 const NetLog::Source& source) override; 1268 const NetLog::Source& source) override;
1271 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 1269 scoped_ptr<StreamSocket> CreateTransportClientSocket(
1272 const AddressList& addresses, 1270 const AddressList& addresses,
1273 NetLog* net_log, 1271 NetLog* net_log,
1274 const NetLog::Source& source) override; 1272 const NetLog::Source& source) override;
1275 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 1273 scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
1276 scoped_ptr<ClientSocketHandle> transport_socket, 1274 scoped_ptr<ClientSocketHandle> transport_socket,
1277 const HostPortPair& host_and_port, 1275 const HostPortPair& host_and_port,
1278 const SSLConfig& ssl_config, 1276 const SSLConfig& ssl_config,
1279 const SSLClientSocketContext& context) override; 1277 const SSLClientSocketContext& context) override;
1280 virtual void ClearSSLSessionCache() override; 1278 void ClearSSLSessionCache() override;
1281 1279
1282 private: 1280 private:
1283 SocketDataProviderArray<DeterministicSocketData> mock_data_; 1281 SocketDataProviderArray<DeterministicSocketData> mock_data_;
1284 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 1282 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
1285 1283
1286 // Store pointers to handed out sockets in case the test wants to get them. 1284 // Store pointers to handed out sockets in case the test wants to get them.
1287 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_; 1285 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_;
1288 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_; 1286 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_;
1289 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 1287 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
1290 1288
1291 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory); 1289 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory);
1292 }; 1290 };
1293 1291
1294 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { 1292 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
1295 public: 1293 public:
1296 MockSOCKSClientSocketPool(int max_sockets, 1294 MockSOCKSClientSocketPool(int max_sockets,
1297 int max_sockets_per_group, 1295 int max_sockets_per_group,
1298 ClientSocketPoolHistograms* histograms, 1296 ClientSocketPoolHistograms* histograms,
1299 TransportClientSocketPool* transport_pool); 1297 TransportClientSocketPool* transport_pool);
1300 1298
1301 virtual ~MockSOCKSClientSocketPool(); 1299 ~MockSOCKSClientSocketPool() override;
1302 1300
1303 // SOCKSClientSocketPool implementation. 1301 // SOCKSClientSocketPool implementation.
1304 virtual int RequestSocket(const std::string& group_name, 1302 int RequestSocket(const std::string& group_name,
1305 const void* socket_params, 1303 const void* socket_params,
1306 RequestPriority priority, 1304 RequestPriority priority,
1307 ClientSocketHandle* handle, 1305 ClientSocketHandle* handle,
1308 const CompletionCallback& callback, 1306 const CompletionCallback& callback,
1309 const BoundNetLog& net_log) override; 1307 const BoundNetLog& net_log) override;
1310 1308
1311 virtual void CancelRequest(const std::string& group_name, 1309 void CancelRequest(const std::string& group_name,
1312 ClientSocketHandle* handle) override; 1310 ClientSocketHandle* handle) override;
1313 virtual void ReleaseSocket(const std::string& group_name, 1311 void ReleaseSocket(const std::string& group_name,
1314 scoped_ptr<StreamSocket> socket, 1312 scoped_ptr<StreamSocket> socket,
1315 int id) override; 1313 int id) override;
1316 1314
1317 private: 1315 private:
1318 TransportClientSocketPool* const transport_pool_; 1316 TransportClientSocketPool* const transport_pool_;
1319 1317
1320 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool); 1318 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
1321 }; 1319 };
1322 1320
1323 // Constants for a successful SOCKS v5 handshake. 1321 // Constants for a successful SOCKS v5 handshake.
1324 extern const char kSOCKS5GreetRequest[]; 1322 extern const char kSOCKS5GreetRequest[];
1325 extern const int kSOCKS5GreetRequestLength; 1323 extern const int kSOCKS5GreetRequestLength;
1326 1324
1327 extern const char kSOCKS5GreetResponse[]; 1325 extern const char kSOCKS5GreetResponse[];
1328 extern const int kSOCKS5GreetResponseLength; 1326 extern const int kSOCKS5GreetResponseLength;
1329 1327
1330 extern const char kSOCKS5OkRequest[]; 1328 extern const char kSOCKS5OkRequest[];
1331 extern const int kSOCKS5OkRequestLength; 1329 extern const int kSOCKS5OkRequestLength;
1332 1330
1333 extern const char kSOCKS5OkResponse[]; 1331 extern const char kSOCKS5OkResponse[];
1334 extern const int kSOCKS5OkResponseLength; 1332 extern const int kSOCKS5OkResponseLength;
1335 1333
1336 } // namespace net 1334 } // namespace net
1337 1335
1338 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1336 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/socket/socket_libevent.h ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698