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

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

Issue 2870030: Implement SSLClientSocketPool. (Closed)
Patch Set: Rebase and fix mac compile error Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
17 #include "base/scoped_vector.h" 17 #include "base/scoped_vector.h"
18 #include "net/base/address_list.h" 18 #include "net/base/address_list.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/base/net_log.h" 21 #include "net/base/net_log.h"
22 #include "net/base/ssl_config_service.h" 22 #include "net/base/ssl_config_service.h"
23 #include "net/base/test_completion_callback.h" 23 #include "net/base/test_completion_callback.h"
24 #include "net/http/http_auth_controller.h"
25 #include "net/http/http_proxy_client_socket_pool.h"
24 #include "net/socket/client_socket_factory.h" 26 #include "net/socket/client_socket_factory.h"
25 #include "net/socket/client_socket_handle.h" 27 #include "net/socket/client_socket_handle.h"
28 #include "net/socket/socks_client_socket_pool.h"
26 #include "net/socket/ssl_client_socket.h" 29 #include "net/socket/ssl_client_socket.h"
27 #include "net/socket/tcp_client_socket_pool.h" 30 #include "net/socket/tcp_client_socket_pool.h"
28 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
29 32
30 namespace net { 33 namespace net {
31 34
32 enum { 35 enum {
33 // A private network error code used by the socket test utility classes. 36 // A private network error code used by the socket test utility classes.
34 // If the |result| member of a MockRead is 37 // If the |result| member of a MockRead is
35 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a 38 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a
36 // marker that indicates the peer will close the connection after the next 39 // marker that indicates the peer will close the connection after the next
37 // MockRead. The other members of that MockRead are ignored. 40 // MockRead. The other members of that MockRead are ignored.
38 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, 41 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000,
39 }; 42 };
40 43
41 class ClientSocket; 44 class ClientSocket;
45 class HttpRequestHeaders;
46 class HttpResponseHeaders;
42 class MockClientSocket; 47 class MockClientSocket;
43 class SSLClientSocket; 48 class SSLClientSocket;
44 49
45 struct MockConnect { 50 struct MockConnect {
46 // Asynchronous connection success. 51 // Asynchronous connection success.
47 MockConnect() : async(true), result(OK) { } 52 MockConnect() : async(true), result(OK) { }
48 MockConnect(bool a, int r) : async(a), result(r) { } 53 MockConnect(bool a, int r) : async(a), result(r) { }
49 54
50 bool async; 55 bool async;
51 int result; 56 int result;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 MockTCPClientSocket* GetMockTCPClientSocket(size_t index) const; 391 MockTCPClientSocket* GetMockTCPClientSocket(size_t index) const;
387 392
388 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory 393 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory
389 // created. 394 // created.
390 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; 395 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const;
391 396
392 // ClientSocketFactory 397 // ClientSocketFactory
393 virtual ClientSocket* CreateTCPClientSocket(const AddressList& addresses, 398 virtual ClientSocket* CreateTCPClientSocket(const AddressList& addresses,
394 NetLog* net_log); 399 NetLog* net_log);
395 virtual SSLClientSocket* CreateSSLClientSocket( 400 virtual SSLClientSocket* CreateSSLClientSocket(
396 ClientSocket* transport_socket, 401 ClientSocketHandle* transport_socket,
397 const std::string& hostname, 402 const std::string& hostname,
398 const SSLConfig& ssl_config); 403 const SSLConfig& ssl_config);
399 404
400 private: 405 private:
401 SocketDataProviderArray<SocketDataProvider> mock_data_; 406 SocketDataProviderArray<SocketDataProvider> mock_data_;
402 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 407 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
403 408
404 // Store pointers to handed out sockets in case the test wants to get them. 409 // Store pointers to handed out sockets in case the test wants to get them.
405 std::vector<MockTCPClientSocket*> tcp_client_sockets_; 410 std::vector<MockTCPClientSocket*> tcp_client_sockets_;
406 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 411 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 494
490 // While an asynchronous IO is pending, we save our user-buffer state. 495 // While an asynchronous IO is pending, we save our user-buffer state.
491 net::IOBuffer* pending_buf_; 496 net::IOBuffer* pending_buf_;
492 int pending_buf_len_; 497 int pending_buf_len_;
493 net::CompletionCallback* pending_callback_; 498 net::CompletionCallback* pending_callback_;
494 }; 499 };
495 500
496 class MockSSLClientSocket : public MockClientSocket { 501 class MockSSLClientSocket : public MockClientSocket {
497 public: 502 public:
498 MockSSLClientSocket( 503 MockSSLClientSocket(
499 net::ClientSocket* transport_socket, 504 net::ClientSocketHandle* transport_socket,
500 const std::string& hostname, 505 const std::string& hostname,
501 const net::SSLConfig& ssl_config, 506 const net::SSLConfig& ssl_config,
502 net::SSLSocketDataProvider* socket); 507 net::SSLSocketDataProvider* socket);
503 ~MockSSLClientSocket(); 508 ~MockSSLClientSocket();
504 509
505 // ClientSocket methods: 510 // ClientSocket methods:
506 virtual int Connect(net::CompletionCallback* callback); 511 virtual int Connect(net::CompletionCallback* callback);
507 virtual void Disconnect(); 512 virtual void Disconnect();
508 513
509 // Socket methods: 514 // Socket methods:
510 virtual int Read(net::IOBuffer* buf, int buf_len, 515 virtual int Read(net::IOBuffer* buf, int buf_len,
511 net::CompletionCallback* callback); 516 net::CompletionCallback* callback);
512 virtual int Write(net::IOBuffer* buf, int buf_len, 517 virtual int Write(net::IOBuffer* buf, int buf_len,
513 net::CompletionCallback* callback); 518 net::CompletionCallback* callback);
514 519
515 // SSLClientSocket methods: 520 // SSLClientSocket methods:
516 virtual void GetSSLInfo(net::SSLInfo* ssl_info); 521 virtual void GetSSLInfo(net::SSLInfo* ssl_info);
517 virtual NextProtoStatus GetNextProto(std::string* proto); 522 virtual NextProtoStatus GetNextProto(std::string* proto);
518 virtual bool wasNpnNegotiated() const; 523 virtual bool wasNpnNegotiated() const;
524 virtual bool setWasNpnNegotiated(bool negotiated);
519 525
520 // This MockSocket does not implement the manual async IO feature. 526 // This MockSocket does not implement the manual async IO feature.
521 virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); } 527 virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); }
522 528
523 private: 529 private:
524 class ConnectCallback; 530 class ConnectCallback;
525 531
526 scoped_ptr<ClientSocket> transport_; 532 scoped_ptr<ClientSocketHandle> transport_;
527 net::SSLSocketDataProvider* data_; 533 net::SSLSocketDataProvider* data_;
534 bool is_npn_state_set_;
535 bool new_npn_value_;
528 }; 536 };
529 537
530 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { 538 class TestSocketRequest : public CallbackRunner< Tuple1<int> > {
531 public: 539 public:
532 TestSocketRequest( 540 TestSocketRequest(
533 std::vector<TestSocketRequest*>* request_order, 541 std::vector<TestSocketRequest*>* request_order,
534 size_t* completion_count) 542 size_t* completion_count)
535 : request_order_(request_order), 543 : request_order_(request_order),
536 completion_count_(completion_count) { 544 completion_count_(completion_count) {
537 DCHECK(request_order); 545 DCHECK(request_order);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 656
649 private: 657 private:
650 ClientSocketFactory* client_socket_factory_; 658 ClientSocketFactory* client_socket_factory_;
651 int release_count_; 659 int release_count_;
652 int cancel_count_; 660 int cancel_count_;
653 ScopedVector<MockConnectJob> job_list_; 661 ScopedVector<MockConnectJob> job_list_;
654 662
655 DISALLOW_COPY_AND_ASSIGN(MockTCPClientSocketPool); 663 DISALLOW_COPY_AND_ASSIGN(MockTCPClientSocketPool);
656 }; 664 };
657 665
666 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
667 public:
668 MockSOCKSClientSocketPool(
669 int max_sockets,
670 int max_sockets_per_group,
671 const scoped_refptr<ClientSocketPoolHistograms>& histograms,
672 const scoped_refptr<TCPClientSocketPool>& tcp_pool);
673
674 // SOCKSClientSocketPool methods.
675 virtual int RequestSocket(const std::string& group_name,
676 const void* socket_params,
677 RequestPriority priority,
678 ClientSocketHandle* handle,
679 CompletionCallback* callback,
680 const BoundNetLog& net_log);
681
682 virtual void CancelRequest(const std::string& group_name,
683 const ClientSocketHandle* handle);
684 virtual void ReleaseSocket(const std::string& group_name,
685 ClientSocket* socket, int id);
686
687 protected:
688 virtual ~MockSOCKSClientSocketPool();
689
690 private:
691 const scoped_refptr<TCPClientSocketPool> tcp_pool_;
692
693 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
694 };
695
696 struct MockHttpAuthControllerData {
697 MockHttpAuthControllerData(std::string header) : auth_header(header) {}
698
699 std::string auth_header;
700 };
701
702 class MockHttpAuthController : public HttpAuthController {
703 public:
704 MockHttpAuthController();
705 void SetMockAuthControllerData(struct MockHttpAuthControllerData* data,
706 size_t data_length);
707
708 // HttpAuthController methods.
709 virtual int MaybeGenerateAuthToken(const HttpRequestInfo* request,
710 CompletionCallback* callback,
711 const BoundNetLog& net_log);
712 virtual void AddAuthorizationHeader(
713 HttpRequestHeaders* authorization_headers);
714 virtual int HandleAuthChallenge(scoped_refptr<HttpResponseHeaders> headers,
715 bool do_not_send_server_auth,
716 bool establishing_tunnel,
717 const BoundNetLog& net_log);
718 virtual void ResetAuth(const std::wstring& username,
719 const std::wstring& password);
720 virtual bool HaveAuthHandler() const;
721 virtual bool HaveAuth() const;
722
723 private:
724 virtual ~MockHttpAuthController() {}
725 const struct MockHttpAuthControllerData& CurrentData() const {
726 DCHECK(data_index_ < data_count_);
727 return data_[data_index_];
728 }
729
730 MockHttpAuthControllerData* data_;
731 size_t data_index_;
732 size_t data_count_;
733 };
734
658 // Constants for a successful SOCKS v5 handshake. 735 // Constants for a successful SOCKS v5 handshake.
659 extern const char kSOCKS5GreetRequest[]; 736 extern const char kSOCKS5GreetRequest[];
660 extern const int kSOCKS5GreetRequestLength; 737 extern const int kSOCKS5GreetRequestLength;
661 738
662 extern const char kSOCKS5GreetResponse[]; 739 extern const char kSOCKS5GreetResponse[];
663 extern const int kSOCKS5GreetResponseLength; 740 extern const int kSOCKS5GreetResponseLength;
664 741
665 extern const char kSOCKS5OkRequest[]; 742 extern const char kSOCKS5OkRequest[];
666 extern const int kSOCKS5OkRequestLength; 743 extern const int kSOCKS5OkRequestLength;
667 744
668 extern const char kSOCKS5OkResponse[]; 745 extern const char kSOCKS5OkResponse[];
669 extern const int kSOCKS5OkResponseLength; 746 extern const int kSOCKS5OkResponseLength;
670 747
671 } // namespace net 748 } // namespace net
672 749
673 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 750 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698