diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 01:41:59 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 01:41:59 +0000 |
commit | 5ecc992a4bf8546b21db89901f2d87e8b4ae1a94 (patch) | |
tree | c96fe65384323dee8a3d7c69dec9ae41ffe96801 /net | |
parent | d871f2ede5f2e511fdb621305ceef207f1c9e52d (diff) | |
download | chromium_src-5ecc992a4bf8546b21db89901f2d87e8b4ae1a94.zip chromium_src-5ecc992a4bf8546b21db89901f2d87e8b4ae1a94.tar.gz chromium_src-5ecc992a4bf8546b21db89901f2d87e8b4ae1a94.tar.bz2 |
There was confusion in the mock socket classes due to
overlapping names. The MockSocket is not actually a socket.
It is an interface for fetching data for reads and writes
on a socket. The MockClientSocket and MockTCPClientSocket
are the actual sockets.
Rename MockSocket to SocketDataProvider.
Rename SSLMockSocket to SSLSocketDataProvider.
Update all tests to reflect name change.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/384024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/flip/flip_network_transaction_unittest.cc | 8 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction_unittest.cc | 380 | ||||
-rw-r--r-- | net/http/http_network_layer_unittest.cc | 4 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 306 | ||||
-rw-r--r-- | net/socket/socket_test_util.cc | 40 | ||||
-rw-r--r-- | net/socket/socket_test_util.h | 90 | ||||
-rw-r--r-- | net/socket/socks5_client_socket_unittest.cc | 6 | ||||
-rw-r--r-- | net/socket/socks_client_socket_unittest.cc | 6 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_unittest.cc | 8 | ||||
-rw-r--r-- | net/websockets/websocket_unittest.cc | 8 |
10 files changed, 430 insertions, 426 deletions
diff --git a/net/flip/flip_network_transaction_unittest.cc b/net/flip/flip_network_transaction_unittest.cc index c60ccdb..5e344a1 100644 --- a/net/flip/flip_network_transaction_unittest.cc +++ b/net/flip/flip_network_transaction_unittest.cc @@ -156,8 +156,8 @@ class FlipNetworkTransactionTest : public PlatformTest { scoped_ptr<FlipNetworkTransaction> trans( new FlipNetworkTransaction(CreateSession(&session_deps))); - StaticMockSocket data(reads, writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(reads, writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -428,8 +428,8 @@ TEST_F(FlipNetworkTransactionTest, DISABLED_CancelledTransaction) { scoped_ptr<FlipNetworkTransaction> trans( new FlipNetworkTransaction(CreateSession(&session_deps))); - StaticMockSocket data(reads, writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(reads, writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index 169e788..95c4e46 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -33,7 +33,7 @@ const int kBufferSize = 128; namespace net { -class FtpMockControlSocket : public DynamicMockSocket { +class FtpSocketDataProvider : public DynamicSocketDataProvider { public: enum State { NONE, @@ -53,7 +53,7 @@ class FtpMockControlSocket : public DynamicMockSocket { QUIT }; - FtpMockControlSocket() + FtpSocketDataProvider() : failure_injection_state_(NONE), multiline_welcome_(false) { Init(); @@ -84,9 +84,9 @@ class FtpMockControlSocket : public DynamicMockSocket { case PRE_PASV: return Verify("PASV\r\n", data, PRE_SIZE, "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); - case PRE_PASV2: - // Parser should also accept format without parentheses. - return Verify("PASV\r\n", data, PRE_CWD, + case PRE_PASV2: + // Parser should also accept format without parentheses. + return Verify("PASV\r\n", data, PRE_CWD, "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); case PRE_QUIT: return Verify("QUIT\r\n", data, QUIT, "221 Goodbye.\r\n"); @@ -111,7 +111,7 @@ class FtpMockControlSocket : public DynamicMockSocket { } virtual void Reset() { - DynamicMockSocket::Reset(); + DynamicSocketDataProvider::Reset(); Init(); } @@ -157,12 +157,12 @@ class FtpMockControlSocket : public DynamicMockSocket { // If true, we will send multiple 230 lines as response after PASS. bool multiline_welcome_; - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocket); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProvider); }; -class FtpMockControlSocketDirectoryListing : public FtpMockControlSocket { +class FtpSocketDataProviderDirectoryListing : public FtpSocketDataProvider { public: - FtpMockControlSocketDirectoryListing() { + FtpSocketDataProviderDirectoryListing() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -185,17 +185,17 @@ class FtpMockControlSocketDirectoryListing : public FtpMockControlSocket { // TODO(phajdan.jr): Also test with "150 Accepted Data Connection". return Verify("LIST\r\n", data, PRE_QUIT, "200 OK\r\n"); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketDirectoryListing); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderDirectoryListing); }; -class FtpMockControlSocketVMSDirectoryListing : public FtpMockControlSocket { +class FtpSocketDataProviderVMSDirectoryListing : public FtpSocketDataProvider { public: - FtpMockControlSocketVMSDirectoryListing() { + FtpSocketDataProviderVMSDirectoryListing() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -222,18 +222,18 @@ class FtpMockControlSocketVMSDirectoryListing : public FtpMockControlSocket { case PRE_LIST: return Verify("LIST *.*;0\r\n", data, PRE_QUIT, "200 OK\r\n"); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketVMSDirectoryListing); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderVMSDirectoryListing); }; -class FtpMockControlSocketVMSDirectoryListingRootDirectory - : public FtpMockControlSocket { +class FtpSocketDataProviderVMSDirectoryListingRootDirectory + : public FtpSocketDataProvider { public: - FtpMockControlSocketVMSDirectoryListingRootDirectory() { + FtpSocketDataProviderVMSDirectoryListingRootDirectory() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -260,18 +260,18 @@ class FtpMockControlSocketVMSDirectoryListingRootDirectory case PRE_LIST: return Verify("LIST *.*;0\r\n", data, PRE_QUIT, "200 OK\r\n"); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } private: DISALLOW_COPY_AND_ASSIGN( - FtpMockControlSocketVMSDirectoryListingRootDirectory); + FtpSocketDataProviderVMSDirectoryListingRootDirectory); }; -class FtpMockControlSocketFileDownload : public FtpMockControlSocket { +class FtpSocketDataProviderFileDownload : public FtpSocketDataProvider { public: - FtpMockControlSocketFileDownload() { + FtpSocketDataProviderFileDownload() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -287,17 +287,17 @@ class FtpMockControlSocketFileDownload : public FtpMockControlSocket { case PRE_RETR: return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownload); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownload); }; -class FtpMockControlSocketVMSFileDownload : public FtpMockControlSocket { +class FtpSocketDataProviderVMSFileDownload : public FtpSocketDataProvider { public: - FtpMockControlSocketVMSFileDownload() { + FtpSocketDataProviderVMSFileDownload() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -319,17 +319,17 @@ class FtpMockControlSocketVMSFileDownload : public FtpMockControlSocket { return Verify("RETR ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_QUIT, "200 OK\r\n"); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketVMSFileDownload); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderVMSFileDownload); }; -class FtpMockControlSocketEscaping : public FtpMockControlSocket { +class FtpSocketDataProviderEscaping : public FtpSocketDataProvider { public: - FtpMockControlSocketEscaping() { + FtpSocketDataProviderEscaping() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -346,18 +346,18 @@ class FtpMockControlSocketEscaping : public FtpMockControlSocket { return Verify("RETR / !\"#$%y\200\201\r\n", data, PRE_QUIT, "200 OK\r\n"); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketEscaping); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderEscaping); }; -class FtpMockControlSocketFileDownloadAcceptedDataConnection - : public FtpMockControlSocketFileDownload { +class FtpSocketDataProviderFileDownloadAcceptedDataConnection + : public FtpSocketDataProviderFileDownload { public: - FtpMockControlSocketFileDownloadAcceptedDataConnection() { + FtpSocketDataProviderFileDownloadAcceptedDataConnection() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -368,19 +368,19 @@ class FtpMockControlSocketFileDownloadAcceptedDataConnection return Verify("RETR /file\r\n", data, PRE_QUIT, "150 Accepted Data Connection\r\n"); default: - return FtpMockControlSocketFileDownload::OnWrite(data); + return FtpSocketDataProviderFileDownload::OnWrite(data); } } private: DISALLOW_COPY_AND_ASSIGN( - FtpMockControlSocketFileDownloadAcceptedDataConnection); + FtpSocketDataProviderFileDownloadAcceptedDataConnection); }; -class FtpMockControlSocketFileDownloadTransferStarting - : public FtpMockControlSocketFileDownload { +class FtpSocketDataProviderFileDownloadTransferStarting + : public FtpSocketDataProviderFileDownload { public: - FtpMockControlSocketFileDownloadTransferStarting() { + FtpSocketDataProviderFileDownloadTransferStarting() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -393,18 +393,18 @@ class FtpMockControlSocketFileDownloadTransferStarting "125 Transfer starting.\r\n" "226 Transfer complete.\r\n"); default: - return FtpMockControlSocketFileDownload::OnWrite(data); + return FtpSocketDataProviderFileDownload::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadTransferStarting); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadTransferStarting); }; -class FtpMockControlSocketFileDownloadInvalidResponse - : public FtpMockControlSocketFileDownload { +class FtpSocketDataProviderFileDownloadInvalidResponse + : public FtpSocketDataProviderFileDownload { public: - FtpMockControlSocketFileDownloadInvalidResponse() { + FtpSocketDataProviderFileDownloadInvalidResponse() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -416,18 +416,18 @@ class FtpMockControlSocketFileDownloadInvalidResponse "500 Evil Response\r\n" "500 More Evil\r\n"); default: - return FtpMockControlSocketFileDownload::OnWrite(data); + return FtpSocketDataProviderFileDownload::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadInvalidResponse); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadInvalidResponse); }; -class FtpMockControlSocketFileDownloadRetrFail - : public FtpMockControlSocketFileDownload { +class FtpSocketDataProviderFileDownloadRetrFail + : public FtpSocketDataProviderFileDownload { public: - FtpMockControlSocketFileDownloadRetrFail() { + FtpSocketDataProviderFileDownloadRetrFail() { } virtual MockWriteResult OnWrite(const std::string& data) { @@ -438,17 +438,17 @@ class FtpMockControlSocketFileDownloadRetrFail return Verify("CWD /file\r\n", data, PRE_QUIT, "550 file is a directory\r\n"); default: - return FtpMockControlSocketFileDownload::OnWrite(data); + return FtpSocketDataProviderFileDownload::OnWrite(data); } } private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadRetrFail); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadRetrFail); }; -class FtpMockControlSocketEvilPasv : public FtpMockControlSocketFileDownload { +class FtpSocketDataProviderEvilPasv : public FtpSocketDataProviderFileDownload { public: - explicit FtpMockControlSocketEvilPasv(const char* pasv_response, + explicit FtpSocketDataProviderEvilPasv(const char* pasv_response, State expected_state) : pasv_response_(pasv_response), expected_state_(expected_state) { @@ -461,7 +461,7 @@ class FtpMockControlSocketEvilPasv : public FtpMockControlSocketFileDownload { case PRE_PASV: return Verify("PASV\r\n", data, expected_state_, pasv_response_); default: - return FtpMockControlSocketFileDownload::OnWrite(data); + return FtpSocketDataProviderFileDownload::OnWrite(data); } } @@ -469,12 +469,12 @@ class FtpMockControlSocketEvilPasv : public FtpMockControlSocketFileDownload { const char* pasv_response_; const State expected_state_; - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketEvilPasv); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderEvilPasv); }; -class FtpMockControlSocketEvilLogin : public FtpMockControlSocketFileDownload { +class FtpSocketDataProviderEvilLogin : public FtpSocketDataProviderFileDownload { public: - FtpMockControlSocketEvilLogin(const char* expected_user, + FtpSocketDataProviderEvilLogin(const char* expected_user, const char* expected_password) : expected_user_(expected_user), expected_password_(expected_password) { @@ -491,7 +491,7 @@ class FtpMockControlSocketEvilLogin : public FtpMockControlSocketFileDownload { return Verify(std::string("PASS ") + expected_password_ + "\r\n", data, PRE_SYST, "230 Welcome\r\n"); default: - return FtpMockControlSocketFileDownload::OnWrite(data); + return FtpSocketDataProviderFileDownload::OnWrite(data); } } @@ -499,14 +499,14 @@ class FtpMockControlSocketEvilLogin : public FtpMockControlSocketFileDownload { const char* expected_user_; const char* expected_password_; - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketEvilLogin); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderEvilLogin); }; -class FtpMockControlSocketCloseConnection : public FtpMockControlSocket { +class FtpSocketDataProviderCloseConnection : public FtpSocketDataProvider { public: - FtpMockControlSocketCloseConnection() { + FtpSocketDataProviderCloseConnection() { } - + virtual MockWriteResult OnWrite(const std::string& data) { if (InjectFault()) return MockWriteResult(true, data.length()); @@ -515,12 +515,12 @@ class FtpMockControlSocketCloseConnection : public FtpMockControlSocket { return Verify("USER anonymous\r\n", data, PRE_QUIT, ""); default: - return FtpMockControlSocket::OnWrite(data); + return FtpSocketDataProvider::OnWrite(data); } } - + private: - DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketCloseConnection); + DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderCloseConnection); }; class FtpNetworkTransactionTest : public PlatformTest { @@ -538,7 +538,7 @@ class FtpNetworkTransactionTest : public PlatformTest { return info; } - void ExecuteTransaction(FtpMockControlSocket* ctrl_socket, + void ExecuteTransaction(FtpSocketDataProvider* ctrl_socket, const char* request, int expected_result) { std::string mock_data("mock-data"); @@ -547,18 +547,18 @@ class FtpNetworkTransactionTest : public PlatformTest { }; // For compatibility with FileZilla, the transaction code will use two data // sockets for directory requests. For more info see http://crbug.com/25316. - StaticMockSocket data_socket1(data_reads, NULL); - StaticMockSocket data_socket2(data_reads, NULL); - mock_socket_factory_.AddMockSocket(ctrl_socket); - mock_socket_factory_.AddMockSocket(&data_socket1); - mock_socket_factory_.AddMockSocket(&data_socket2); + StaticSocketDataProvider data1(data_reads, NULL); + StaticSocketDataProvider data2(data_reads, NULL); + mock_socket_factory_.AddSocketDataProvider(ctrl_socket); + mock_socket_factory_.AddSocketDataProvider(&data1); + mock_socket_factory_.AddSocketDataProvider(&data2); FtpRequestInfo request_info = GetRequestInfo(request); EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_, NULL)); EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); EXPECT_EQ(expected_result, callback_.WaitForResult()); - EXPECT_EQ(FtpMockControlSocket::QUIT, ctrl_socket->state()); + EXPECT_EQ(FtpSocketDataProvider::QUIT, ctrl_socket->state()); if (expected_result == OK) { scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); memset(io_buffer->data(), 0, kBufferSize); @@ -571,10 +571,10 @@ class FtpNetworkTransactionTest : public PlatformTest { EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); } - void TransactionFailHelper(FtpMockControlSocket* ctrl_socket, + void TransactionFailHelper(FtpSocketDataProvider* ctrl_socket, const char* request, - FtpMockControlSocket::State state, - FtpMockControlSocket::State next_state, + FtpSocketDataProvider::State state, + FtpSocketDataProvider::State next_state, const char* response, int expected_result) { ctrl_socket->InjectFailure(state, next_state, response); @@ -599,30 +599,30 @@ TEST_F(FtpNetworkTransactionTest, FailedLookup) { } TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; ctrl_socket.set_multiline_welcome(true); ExecuteTransaction(&ctrl_socket, "ftp://host", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads2) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; ctrl_socket.set_short_read_limit(2); ExecuteTransaction(&ctrl_socket, "ftp://host", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads5) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; ctrl_socket.set_short_read_limit(5); ExecuteTransaction(&ctrl_socket, "ftp://host", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcomeShort) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; // The client will not consume all three 230 lines. That's good, we want to // test that scenario. ctrl_socket.allow_unconsumed_reads(true); @@ -632,52 +632,52 @@ TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcomeShort) { } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionVMS) { - FtpMockControlSocketVMSDirectoryListing ctrl_socket; + FtpSocketDataProviderVMSDirectoryListing ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host/dir", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionVMSRootDirectory) { - FtpMockControlSocketVMSDirectoryListingRootDirectory ctrl_socket; + FtpSocketDataProviderVMSDirectoryListingRootDirectory ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransaction) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionMultilineWelcome) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; ctrl_socket.set_multiline_welcome(true); ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads2) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; ctrl_socket.set_short_read_limit(2); ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads5) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; ctrl_socket.set_short_read_limit(5); ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionVMS) { - FtpMockControlSocketVMSFileDownload ctrl_socket; + FtpSocketDataProviderVMSFileDownload ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionAcceptedDataConnection) { - FtpMockControlSocketFileDownloadAcceptedDataConnection ctrl_socket; + FtpSocketDataProviderFileDownloadAcceptedDataConnection ctrl_socket; std::string mock_data("mock-data"); MockRead data_reads[] = { MockRead(mock_data.c_str()), }; - StaticMockSocket data_socket1(data_reads, NULL); - mock_socket_factory_.AddMockSocket(&ctrl_socket); - mock_socket_factory_.AddMockSocket(&data_socket1); + StaticSocketDataProvider data_socket1(data_reads, NULL); + mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); + mock_socket_factory_.AddSocketDataProvider(&data_socket1); FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); // Start the transaction. @@ -686,7 +686,7 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionAcceptedDataConnection) { EXPECT_EQ(OK, callback_.WaitForResult()); // The transaction fires the callback when we can start reading data. - EXPECT_EQ(FtpMockControlSocket::PRE_QUIT, ctrl_socket.state()); + EXPECT_EQ(FtpSocketDataProvider::PRE_QUIT, ctrl_socket.state()); EXPECT_EQ(LOAD_STATE_SENDING_REQUEST, transaction_.GetLoadState()); scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); memset(io_buffer->data(), 0, kBufferSize); @@ -711,57 +711,57 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionAcceptedDataConnection) { // Make sure the transaction finishes cleanly. EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); EXPECT_EQ(OK, callback_.WaitForResult()); - EXPECT_EQ(FtpMockControlSocket::QUIT, ctrl_socket.state()); + EXPECT_EQ(FtpSocketDataProvider::QUIT, ctrl_socket.state()); EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionTransferStarting) { - FtpMockControlSocketFileDownloadTransferStarting ctrl_socket; + FtpSocketDataProviderFileDownloadTransferStarting ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionInvalidResponse) { - FtpMockControlSocketFileDownloadInvalidResponse ctrl_socket; + FtpSocketDataProviderFileDownloadInvalidResponse ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort1) { - FtpMockControlSocketEvilPasv ctrl_socket("227 Portscan (127,0,0,1,0,22)\r\n", - FtpMockControlSocket::PRE_QUIT); + FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,0,22)\r\n", + FtpSocketDataProvider::PRE_QUIT); ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort2) { // Still unsafe. 1 * 256 + 2 = 258, which is < 1024. - FtpMockControlSocketEvilPasv ctrl_socket("227 Portscan (127,0,0,1,1,2)\r\n", - FtpMockControlSocket::PRE_QUIT); + FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,1,2)\r\n", + FtpSocketDataProvider::PRE_QUIT); ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort3) { // Still unsafe. 3 * 256 + 4 = 772, which is < 1024. - FtpMockControlSocketEvilPasv ctrl_socket("227 Portscan (127,0,0,1,3,4)\r\n", - FtpMockControlSocket::PRE_QUIT); + FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,3,4)\r\n", + FtpSocketDataProvider::PRE_QUIT); ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort4) { // Unsafe. 8 * 256 + 1 = 2049, which is used by nfs. - FtpMockControlSocketEvilPasv ctrl_socket("227 Portscan (127,0,0,1,8,1)\r\n", - FtpMockControlSocket::PRE_QUIT); + FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,8,1)\r\n", + FtpSocketDataProvider::PRE_QUIT); ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { - FtpMockControlSocketEvilPasv ctrl_socket( - "227 Portscan (10,1,2,3,4,123,456)\r\n", FtpMockControlSocket::PRE_SIZE); + FtpSocketDataProviderEvilPasv ctrl_socket( + "227 Portscan (10,1,2,3,4,123,456)\r\n", FtpSocketDataProvider::PRE_SIZE); std::string mock_data("mock-data"); MockRead data_reads[] = { MockRead(mock_data.c_str()), }; - StaticMockSocket data_socket1(data_reads, NULL); - mock_socket_factory_.AddMockSocket(&ctrl_socket); - mock_socket_factory_.AddMockSocket(&data_socket1); + StaticSocketDataProvider data_socket1(data_reads, NULL); + mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); + mock_socket_factory_.AddSocketDataProvider(&data_socket1); FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); // Start the transaction. @@ -785,31 +785,31 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilLoginBadUsername) { - FtpMockControlSocketEvilLogin ctrl_socket("hello%0Aworld", "test"); + FtpSocketDataProviderEvilLogin ctrl_socket("hello%0Aworld", "test"); ExecuteTransaction(&ctrl_socket, "ftp://hello%0Aworld:test@host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilLoginBadPassword) { - FtpMockControlSocketEvilLogin ctrl_socket("test", "hello%0Dworld"); + FtpSocketDataProviderEvilLogin ctrl_socket("test", "hello%0Dworld"); ExecuteTransaction(&ctrl_socket, "ftp://test:hello%0Dworld@host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionSpaceInLogin) { - FtpMockControlSocketEvilLogin ctrl_socket("hello world", "test"); + FtpSocketDataProviderEvilLogin ctrl_socket("hello world", "test"); ExecuteTransaction(&ctrl_socket, "ftp://hello%20world:test@host/file", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionSpaceInPassword) { - FtpMockControlSocketEvilLogin ctrl_socket("test", "hello world"); + FtpSocketDataProviderEvilLogin ctrl_socket("test", "hello world"); ExecuteTransaction(&ctrl_socket, "ftp://test:hello%20world@host/file", OK); } TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { - FtpMockControlSocket ctrl_socket1; - ctrl_socket1.InjectFailure(FtpMockControlSocket::PRE_PASSWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider ctrl_socket1; + ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, + FtpSocketDataProvider::PRE_QUIT, "530 Login authentication failed\r\n"); - mock_socket_factory_.AddMockSocket(&ctrl_socket1); + mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); @@ -825,8 +825,8 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { MockWrite ctrl_writes[] = { MockWrite("QUIT\r\n"), }; - StaticMockSocket ctrl_socket2(ctrl_reads, ctrl_writes); - mock_socket_factory_.AddMockSocket(&ctrl_socket2); + StaticSocketDataProvider ctrl_socket2(ctrl_reads, ctrl_writes); + mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"foo\nownz0red", L"innocent", &callback_)); @@ -834,11 +834,11 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { } TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { - FtpMockControlSocket ctrl_socket1; - ctrl_socket1.InjectFailure(FtpMockControlSocket::PRE_PASSWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider ctrl_socket1; + ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, + FtpSocketDataProvider::PRE_QUIT, "530 Login authentication failed\r\n"); - mock_socket_factory_.AddMockSocket(&ctrl_socket1); + mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); @@ -856,8 +856,8 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { MockWrite("USER innocent\r\n"), MockWrite("QUIT\r\n"), }; - StaticMockSocket ctrl_socket2(ctrl_reads, ctrl_writes); - mock_socket_factory_.AddMockSocket(&ctrl_socket2); + StaticSocketDataProvider ctrl_socket2(ctrl_reads, ctrl_writes); + mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", L"foo\nownz0red", &callback_)); @@ -865,223 +865,223 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { } TEST_F(FtpNetworkTransactionTest, Escaping) { - FtpMockControlSocketEscaping ctrl_socket; + FtpSocketDataProviderEscaping ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", OK); } // Regression test for http://crbug.com/25023. TEST_F(FtpNetworkTransactionTest, CloseConnection) { - FtpMockControlSocketCloseConnection ctrl_socket; + FtpSocketDataProviderCloseConnection ctrl_socket; ExecuteTransaction(&ctrl_socket, "ftp://host", ERR_EMPTY_RESPONSE); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_USER, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_USER, + FtpSocketDataProvider::PRE_QUIT, "500 no such user\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailPass) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_PASSWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PASSWD, + FtpSocketDataProvider::PRE_QUIT, "530 Login authentication failed\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailSyst) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_SYST, - FtpMockControlSocket::PRE_PWD, + FtpSocketDataProvider::PRE_SYST, + FtpSocketDataProvider::PRE_PWD, "500 failed syst\r\n", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailPwd) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_PWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PWD, + FtpSocketDataProvider::PRE_QUIT, "500 failed pwd\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailType) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_TYPE, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_TYPE, + FtpSocketDataProvider::PRE_QUIT, "500 failed type\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailPasv) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_PASV, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PASV, + FtpSocketDataProvider::PRE_QUIT, "500 failed pasv\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMalformedMdtm) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_MDTM, - FtpMockControlSocket::PRE_RETR, + FtpSocketDataProvider::PRE_MDTM, + FtpSocketDataProvider::PRE_RETR, "213 foobar\r\n", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailMdtm) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_MDTM, - FtpMockControlSocket::PRE_RETR, + FtpSocketDataProvider::PRE_MDTM, + FtpSocketDataProvider::PRE_RETR, "500 failed mdtm\r\n", OK); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailPasv2) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_PASV2, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PASV2, + FtpSocketDataProvider::PRE_QUIT, "500 failed pasv2\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailCwd) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_CWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_CWD, + FtpSocketDataProvider::PRE_QUIT, "500 failed cwd\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFileNotFound) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_CWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_CWD, + FtpSocketDataProvider::PRE_QUIT, "550 cannot open file\r\n", ERR_FILE_NOT_FOUND); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailList) { - FtpMockControlSocketDirectoryListing ctrl_socket; + FtpSocketDataProviderDirectoryListing ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host", - FtpMockControlSocket::PRE_LIST, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_LIST, + FtpSocketDataProvider::PRE_QUIT, "500 failed list\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailUser) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_USER, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_USER, + FtpSocketDataProvider::PRE_QUIT, "500 no such user\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailPass) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_PASSWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PASSWD, + FtpSocketDataProvider::PRE_QUIT, "530 Login authentication failed\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailSyst) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_SYST, - FtpMockControlSocket::PRE_PWD, + FtpSocketDataProvider::PRE_SYST, + FtpSocketDataProvider::PRE_PWD, "500 failed syst\r\n", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailPwd) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_PWD, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PWD, + FtpSocketDataProvider::PRE_QUIT, "500 failed pwd\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailType) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_TYPE, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_TYPE, + FtpSocketDataProvider::PRE_QUIT, "500 failed type\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailPasv) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_PASV, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_PASV, + FtpSocketDataProvider::PRE_QUIT, "500 failed pasv\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailMdtm) { - FtpMockControlSocketFileDownload ctrl_socket; + FtpSocketDataProviderFileDownload ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_MDTM, - FtpMockControlSocket::PRE_RETR, + FtpSocketDataProvider::PRE_MDTM, + FtpSocketDataProvider::PRE_RETR, "500 failed mdtm\r\n", OK); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFailRetr) { - FtpMockControlSocketFileDownloadRetrFail ctrl_socket; + FtpSocketDataProviderFileDownloadRetrFail ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_RETR, - FtpMockControlSocket::PRE_QUIT, + FtpSocketDataProvider::PRE_RETR, + FtpSocketDataProvider::PRE_QUIT, "500 failed retr\r\n", ERR_FAILED); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionFileNotFound) { - FtpMockControlSocketFileDownloadRetrFail ctrl_socket; + FtpSocketDataProviderFileDownloadRetrFail ctrl_socket; TransactionFailHelper(&ctrl_socket, "ftp://host/file", - FtpMockControlSocket::PRE_RETR, - FtpMockControlSocket::PRE_PASV2, + FtpSocketDataProvider::PRE_RETR, + FtpSocketDataProvider::PRE_PASV2, "550 cannot open file\r\n", ERR_FILE_NOT_FOUND); } diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index dcc9405..d8240e1 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -62,8 +62,8 @@ TEST_F(HttpNetworkLayerTest, GET) { "Connection: keep-alive\r\n" "User-Agent: Foo/1.0\r\n\r\n"), }; - net::StaticMockSocket data(data_reads, data_writes); - mock_socket_factory.AddMockSocket(&data); + net::StaticSocketDataProvider data(data_reads, data_writes); + mock_socket_factory.AddSocketDataProvider(&data); net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver, net::ProxyService::CreateNull(), diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index d929075..c06e21a4 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -103,8 +103,8 @@ class HttpNetworkTransactionTest : public PlatformTest { request.url = GURL("http://www.google.com/"); request.load_flags = 0; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -372,8 +372,8 @@ TEST_F(HttpNetworkTransactionTest, Head) { MockRead(false, ERR_UNEXPECTED), // Should not be reached. }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -417,8 +417,8 @@ TEST_F(HttpNetworkTransactionTest, ReuseConnection) { MockRead("world"), MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); const char* kExpectedResponseData[] = { "hello", "world" @@ -471,8 +471,8 @@ TEST_F(HttpNetworkTransactionTest, Ignores100) { MockRead("hello world"), MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -513,8 +513,8 @@ TEST_F(HttpNetworkTransactionTest, Ignores1xx) { MockRead("hello world"), MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -553,16 +553,16 @@ void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( MockRead("hello"), read_failure, // Now, we reuse the connection and fail the first read. }; - StaticMockSocket data1(data1_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data1_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data1); MockRead data2_reads[] = { MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), MockRead("world"), MockRead(true, OK), }; - StaticMockSocket data2(data2_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data2(data2_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data2); const char* kExpectedResponseData[] = { "hello", "world" @@ -618,8 +618,8 @@ TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { MockRead("hello world"), MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -701,10 +701,10 @@ TEST_F(HttpNetworkTransactionTest, BasicAuth) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -763,8 +763,8 @@ TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { MockRead(false, ERR_FAILED), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; int rv = trans->Start(&request, &callback, NULL); @@ -817,8 +817,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -894,8 +894,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -974,8 +974,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -1056,8 +1056,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { MockRead(false, ERR_UNEXPECTED), // Should not be reached. }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -1137,8 +1137,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { MockRead(false, ERR_UNEXPECTED), // Should not be reached. }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -1189,8 +1189,8 @@ void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( MockRead(false, ERR_UNEXPECTED), // Should not be reached. }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -1444,12 +1444,12 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - StaticMockSocket data3(data_reads3, data_writes3); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); - session_deps.socket_factory.AddMockSocket(&data3); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + StaticSocketDataProvider data3(data_reads3, data_writes3); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); + session_deps.socket_factory.AddSocketDataProvider(&data3); TestCompletionCallback callback1; @@ -1583,10 +1583,10 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -1753,12 +1753,12 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - StaticMockSocket data3(data_reads3, data_writes3); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); - session_deps.socket_factory.AddMockSocket(&data3); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + StaticSocketDataProvider data3(data_reads3, data_writes3); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); + session_deps.socket_factory.AddSocketDataProvider(&data3); TestCompletionCallback callback1; @@ -1851,8 +1851,8 @@ TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { MockRead("\r\nBODY"), MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -1898,8 +1898,8 @@ TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { MockRead(false, ERR_UNEXPECTED), // Should not be reached. }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -1947,8 +1947,8 @@ TEST_F(HttpNetworkTransactionTest, RecycleSocket) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -2004,8 +2004,8 @@ TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -2073,7 +2073,7 @@ TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { MockWrite(false, 93), // POST MockWrite(false, ERR_CONNECTION_ABORTED), // POST data }; - StaticMockSocket data1(data_reads1, data_writes1); + StaticSocketDataProvider data1(data_reads1, data_writes1); // The second socket is used for the second attempt of transaction 2. @@ -2088,10 +2088,10 @@ TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { MockWrite(false, 93), // POST MockWrite(false, 3), // POST data }; - StaticMockSocket data2(data_reads2, data_writes2); + StaticSocketDataProvider data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); const char* kExpectedResponseData[] = { "hello world", "welcome" @@ -2169,10 +2169,10 @@ TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -2262,12 +2262,12 @@ TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - StaticMockSocket data3(data_reads3, data_writes3); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); - session_deps.socket_factory.AddMockSocket(&data3); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + StaticSocketDataProvider data3(data_reads3, data_writes3); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); + session_deps.socket_factory.AddSocketDataProvider(&data3); TestCompletionCallback callback1; @@ -2355,10 +2355,10 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -2438,10 +2438,10 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -2504,8 +2504,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); TestCompletionCallback callback1; @@ -2562,10 +2562,10 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -2646,12 +2646,12 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { MockRead(false, OK), }; - StaticMockSocket data1(data_reads1, data_writes1); - StaticMockSocket data2(data_reads2, data_writes2); - StaticMockSocket data3(data_reads3, data_writes3); - session_deps.socket_factory.AddMockSocket(&data1); - session_deps.socket_factory.AddMockSocket(&data2); - session_deps.socket_factory.AddMockSocket(&data3); + StaticSocketDataProvider data1(data_reads1, data_writes1); + StaticSocketDataProvider data2(data_reads2, data_writes2); + StaticSocketDataProvider data3(data_reads3, data_writes3); + session_deps.socket_factory.AddSocketDataProvider(&data1); + session_deps.socket_factory.AddSocketDataProvider(&data2); + session_deps.socket_factory.AddSocketDataProvider(&data3); TestCompletionCallback callback1; @@ -2763,15 +2763,15 @@ TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { MockRead(false, OK), }; - StaticMockSocket ssl_bad_certificate; - StaticMockSocket data(data_reads, data_writes); - MockSSLSocket ssl_bad(true, ERR_CERT_AUTHORITY_INVALID); - MockSSLSocket ssl(true, OK); + StaticSocketDataProvider ssl_bad_certificate; + StaticSocketDataProvider data(data_reads, data_writes); + SSLSocketDataProvider ssl_bad(true, ERR_CERT_AUTHORITY_INVALID); + SSLSocketDataProvider ssl(true, OK); - session_deps.socket_factory.AddMockSocket(&ssl_bad_certificate); - session_deps.socket_factory.AddMockSocket(&data); - session_deps.socket_factory.AddMockSSLSocket(&ssl_bad); - session_deps.socket_factory.AddMockSSLSocket(&ssl); + session_deps.socket_factory.AddSocketDataProvider(&ssl_bad_certificate); + session_deps.socket_factory.AddSocketDataProvider(&data); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_bad); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback callback; @@ -2831,15 +2831,15 @@ TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { MockRead(false, OK), }; - StaticMockSocket ssl_bad_certificate(proxy_reads, proxy_writes); - StaticMockSocket data(data_reads, data_writes); - MockSSLSocket ssl_bad(true, ERR_CERT_AUTHORITY_INVALID); - MockSSLSocket ssl(true, OK); + StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); + StaticSocketDataProvider data(data_reads, data_writes); + SSLSocketDataProvider ssl_bad(true, ERR_CERT_AUTHORITY_INVALID); + SSLSocketDataProvider ssl(true, OK); - session_deps.socket_factory.AddMockSocket(&ssl_bad_certificate); - session_deps.socket_factory.AddMockSocket(&data); - session_deps.socket_factory.AddMockSSLSocket(&ssl_bad); - session_deps.socket_factory.AddMockSSLSocket(&ssl); + session_deps.socket_factory.AddSocketDataProvider(&ssl_bad_certificate); + session_deps.socket_factory.AddSocketDataProvider(&data); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_bad); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback callback; @@ -2893,8 +2893,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -2931,8 +2931,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -2967,8 +2967,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3003,8 +3003,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3039,8 +3039,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3077,8 +3077,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3115,8 +3115,8 @@ TEST_F(HttpNetworkTransactionTest, MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3152,8 +3152,8 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3187,15 +3187,15 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { }; MockRead data_reads[] = { - MockWrite(true, read_buffer, arraysize(read_buffer)), + MockRead(true, read_buffer, arraysize(read_buffer)), MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), MockRead("Payload"), MockRead(false, OK) }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3246,11 +3246,11 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { MockRead(false, OK) }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); - MockSSLSocket ssl(true, OK); - session_deps.socket_factory.AddMockSSLSocket(&ssl); + SSLSocketDataProvider ssl(true, OK); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback callback; @@ -3305,8 +3305,8 @@ TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { MockRead(false, OK) }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3362,11 +3362,11 @@ TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { MockRead(false, OK) }; - StaticMockSocket data(data_reads, data_writes); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + session_deps.socket_factory.AddSocketDataProvider(&data); - MockSSLSocket ssl(true, OK); - session_deps.socket_factory.AddMockSSLSocket(&ssl); + SSLSocketDataProvider ssl(true, OK); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback callback; @@ -3532,8 +3532,8 @@ TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) { MockRead data_reads[] = { MockRead(false, ERR_FAILED), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); // Issue a request, containing an HTTP referrer. HttpRequestInfo request; @@ -3587,8 +3587,8 @@ TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { // Connect up a mock socket which will fail with ERR_UNEXPECTED during the // first read -- this won't be reached as the host resolution will fail first. MockRead data_reads[] = { MockRead(false, ERR_UNEXPECTED) }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); // Issue a request, asking to bypass the cache(s). HttpRequestInfo request; @@ -3620,8 +3620,8 @@ TEST_F(HttpNetworkTransactionTest, RequestWriteError) { MockWrite write_failure[] = { MockWrite(true, ERR_CONNECTION_RESET), }; - StaticMockSocket data(NULL, write_failure); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(NULL, write_failure); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3650,8 +3650,8 @@ TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { MockRead(false, OK), }; - StaticMockSocket data(data_reads, NULL); - session_deps.socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, NULL); + session_deps.socket_factory.AddSocketDataProvider(&data); TestCompletionCallback callback; @@ -3703,8 +3703,8 @@ TEST_F(HttpNetworkTransactionTest, DrainResetOK) { MockRead(true, ERR_CONNECTION_RESET), }; - StaticMockSocket data1(data_reads1, data_writes1); - session_deps.socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + session_deps.socket_factory.AddSocketDataProvider(&data1); // After calling trans->RestartWithAuth(), this is the request we should // be issuing -- the final header line contains the credentials. @@ -3723,8 +3723,8 @@ TEST_F(HttpNetworkTransactionTest, DrainResetOK) { MockRead(false, OK), }; - StaticMockSocket data2(data_reads2, data_writes2); - session_deps.socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data2(data_reads2, data_writes2); + session_deps.socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback1; @@ -3772,11 +3772,11 @@ TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { MockRead(false, OK) }; - StaticMockSocket data(proxy_reads, NULL); - MockSSLSocket ssl(true, OK); + StaticSocketDataProvider data(proxy_reads, NULL); + SSLSocketDataProvider ssl(true, OK); - session_deps.socket_factory.AddMockSocket(&data); - session_deps.socket_factory.AddMockSSLSocket(&ssl); + session_deps.socket_factory.AddSocketDataProvider(&data); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback callback; diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index 5433a65..8b7fcbf 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -62,9 +62,9 @@ void MockClientSocket::RunCallback(net::CompletionCallback* callback, } MockTCPClientSocket::MockTCPClientSocket(const net::AddressList& addresses, - net::MockSocket* socket) + net::SocketDataProvider* data) : addresses_(addresses), - data_(socket), + data_(data), read_offset_(0), read_data_(true, net::ERR_UNEXPECTED), need_read_data_(true) { @@ -163,9 +163,9 @@ MockSSLClientSocket::MockSSLClientSocket( net::ClientSocket* transport_socket, const std::string& hostname, const net::SSLConfig& ssl_config, - net::MockSSLSocket* socket) + net::SSLSocketDataProvider* data) : transport_(transport_socket), - data_(socket) { + data_(data) { DCHECK(data_); } @@ -211,11 +211,11 @@ int MockSSLClientSocket::Write(net::IOBuffer* buf, int buf_len, return transport_->Write(buf, buf_len, callback); } -MockRead StaticMockSocket::GetNextRead() { +MockRead StaticSocketDataProvider::GetNextRead() { return reads_[read_index_++]; } -MockWriteResult StaticMockSocket::OnWrite(const std::string& data) { +MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) { if (!writes_) { // Not using mock writes; succeed synchronously. return MockWriteResult(false, data.length()); @@ -236,17 +236,17 @@ MockWriteResult StaticMockSocket::OnWrite(const std::string& data) { return MockWriteResult(w->async, result); } -void StaticMockSocket::Reset() { +void StaticSocketDataProvider::Reset() { read_index_ = 0; write_index_ = 0; } -DynamicMockSocket::DynamicMockSocket() +DynamicSocketDataProvider::DynamicSocketDataProvider() : short_read_limit_(0), allow_unconsumed_reads_(false) { } -MockRead DynamicMockSocket::GetNextRead() { +MockRead DynamicSocketDataProvider::GetNextRead() { if (reads_.empty()) return MockRead(true, ERR_UNEXPECTED); MockRead result = reads_.front(); @@ -260,28 +260,30 @@ MockRead DynamicMockSocket::GetNextRead() { return result; } -void DynamicMockSocket::Reset() { +void DynamicSocketDataProvider::Reset() { reads_.clear(); } -void DynamicMockSocket::SimulateRead(const char* data) { +void DynamicSocketDataProvider::SimulateRead(const char* data) { if (!allow_unconsumed_reads_) { EXPECT_TRUE(reads_.empty()) << "Unconsumed read: " << reads_.front().data; } reads_.push_back(MockRead(data)); } -void MockClientSocketFactory::AddMockSocket(MockSocket* socket) { - mock_sockets_.Add(socket); +void MockClientSocketFactory::AddSocketDataProvider( + SocketDataProvider* data) { + mock_data_.Add(data); } -void MockClientSocketFactory::AddMockSSLSocket(MockSSLSocket* socket) { - mock_ssl_sockets_.Add(socket); +void MockClientSocketFactory::AddSSLSocketDataProvider( + SSLSocketDataProvider* data) { + mock_ssl_data_.Add(data); } void MockClientSocketFactory::ResetNextMockIndexes() { - mock_sockets_.ResetNextIndex(); - mock_ssl_sockets_.ResetNextIndex(); + mock_data_.ResetNextIndex(); + mock_ssl_data_.ResetNextIndex(); } MockTCPClientSocket* MockClientSocketFactory::GetMockTCPClientSocket( @@ -297,7 +299,7 @@ MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( ClientSocket* MockClientSocketFactory::CreateTCPClientSocket( const AddressList& addresses) { MockTCPClientSocket* socket = - new MockTCPClientSocket(addresses, mock_sockets_.GetNext()); + new MockTCPClientSocket(addresses, mock_data_.GetNext()); tcp_client_sockets_.push_back(socket); return socket; } @@ -308,7 +310,7 @@ SSLClientSocket* MockClientSocketFactory::CreateSSLClientSocket( const SSLConfig& ssl_config) { MockSSLClientSocket* socket = new MockSSLClientSocket(transport_socket, hostname, ssl_config, - mock_ssl_sockets_.GetNext()); + mock_ssl_data_.GetNext()); ssl_client_sockets_.push_back(socket); return socket; } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index b4a260c..0e1380c 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -74,11 +74,13 @@ struct MockWriteResult { int result; }; -class MockSocket { +// The SocketDataProvider is an interface used by the MockClientSocket +// for getting data about individual reads and writes on the socket. +class SocketDataProvider { public: - MockSocket() {} + SocketDataProvider() {} - virtual ~MockSocket() {} + virtual ~SocketDataProvider() {} virtual MockRead GetNextRead() = 0; virtual MockWriteResult OnWrite(const std::string& data) = 0; virtual void Reset() = 0; @@ -88,18 +90,19 @@ class MockSocket { private: MockConnect connect_; - DISALLOW_COPY_AND_ASSIGN(MockSocket); + DISALLOW_COPY_AND_ASSIGN(SocketDataProvider); }; -// MockSocket which responds based on static tables of mock reads and writes. -class StaticMockSocket : public MockSocket { +// SocketDataProvider which responds based on static tables of mock reads and +// writes. +class StaticSocketDataProvider : public SocketDataProvider { public: - StaticMockSocket() : reads_(NULL), read_index_(0), + StaticSocketDataProvider() : reads_(NULL), read_index_(0), writes_(NULL), write_index_(0) {} - StaticMockSocket(MockRead* r, MockWrite* w) : reads_(r), read_index_(0), - writes_(w), write_index_(0) {} + StaticSocketDataProvider(MockRead* r, MockWrite* w) : reads_(r), + read_index_(0), writes_(w), write_index_(0) {} - // MockSocket methods: + // SocketDataProvider methods: virtual MockRead GetNextRead(); virtual MockWriteResult OnWrite(const std::string& data); virtual void Reset(); @@ -117,19 +120,18 @@ class StaticMockSocket : public MockSocket { MockWrite* writes_; int write_index_; - DISALLOW_COPY_AND_ASSIGN(StaticMockSocket); + DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); }; -// MockSocket which can make decisions about next mock reads based on -// received writes. It can also be used to enforce order of operations, -// for example that tested code must send the "Hello!" message before -// receiving response. This is useful for testing conversation-like -// protocols like FTP. -class DynamicMockSocket : public MockSocket { +// SocketDataProvider which can make decisions about next mock reads based on +// received writes. It can also be used to enforce order of operations, for +// example that tested code must send the "Hello!" message before receiving +// response. This is useful for testing conversation-like protocols like FTP. +class DynamicSocketDataProvider : public SocketDataProvider { public: - DynamicMockSocket(); + DynamicSocketDataProvider(); - // MockSocket methods: + // SocketDataProvider methods: virtual MockRead GetNextRead(); virtual MockWriteResult OnWrite(const std::string& data) = 0; virtual void Reset(); @@ -154,34 +156,34 @@ class DynamicMockSocket : public MockSocket { // mock the next read. bool allow_unconsumed_reads_; - DISALLOW_COPY_AND_ASSIGN(DynamicMockSocket); + DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider); }; -// MockSSLSockets only need to keep track of the return code from calls to -// Connect(). -struct MockSSLSocket { - MockSSLSocket(bool async, int result) : connect(async, result) { } +// SSLSocketDataProviders only need to keep track of the return code from calls +// to Connect(). +struct SSLSocketDataProvider { + SSLSocketDataProvider(bool async, int result) : connect(async, result) { } MockConnect connect; }; -// Holds an array of Mock{SSL,}Socket elements. As Mock{TCP,SSL}ClientSocket +// Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}ClientSocket // objects get instantiated, they take their data from the i'th element of this // array. template<typename T> -class MockSocketArray { +class SocketDataProviderArray { public: - MockSocketArray() : next_index_(0) { + SocketDataProviderArray() : next_index_(0) { } T* GetNext() { - DCHECK(next_index_ < sockets_.size()); - return sockets_[next_index_++]; + DCHECK(next_index_ < data_providers_.size()); + return data_providers_[next_index_++]; } - void Add(T* socket) { - DCHECK(socket); - sockets_.push_back(socket); + void Add(T* data_provider) { + DCHECK(data_provider); + data_providers_.push_back(data_provider); } void ResetNextIndex() { @@ -189,12 +191,12 @@ class MockSocketArray { } private: - // Index of the next |sockets| element to use. Not an iterator because those - // are invalidated on vector reallocation. + // Index of the next |data_providers_| element to use. Not an iterator + // because those are invalidated on vector reallocation. size_t next_index_; - // Mock sockets to be returned. - std::vector<T*> sockets_; + // SocketDataProviders to be returned. + std::vector<T*> data_providers_; }; class MockTCPClientSocket; @@ -207,8 +209,8 @@ class MockSSLClientSocket; // socket types. class MockClientSocketFactory : public ClientSocketFactory { public: - void AddMockSocket(MockSocket* socket); - void AddMockSSLSocket(MockSSLSocket* socket); + void AddSocketDataProvider(SocketDataProvider* socket); + void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); void ResetNextMockIndexes(); // Return |index|-th MockTCPClientSocket (starting from 0) that the factory @@ -227,8 +229,8 @@ class MockClientSocketFactory : public ClientSocketFactory { const SSLConfig& ssl_config); private: - MockSocketArray<MockSocket> mock_sockets_; - MockSocketArray<MockSSLSocket> mock_ssl_sockets_; + SocketDataProviderArray<SocketDataProvider> mock_data_; + SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; // Store pointers to handed out sockets in case the test wants to get them. std::vector<MockTCPClientSocket*> tcp_client_sockets_; @@ -273,7 +275,7 @@ class MockClientSocket : public net::SSLClientSocket { class MockTCPClientSocket : public MockClientSocket { public: MockTCPClientSocket(const net::AddressList& addresses, - net::MockSocket* socket); + net::SocketDataProvider* socket); // ClientSocket methods: virtual int Connect(net::CompletionCallback* callback, @@ -290,7 +292,7 @@ class MockTCPClientSocket : public MockClientSocket { private: net::AddressList addresses_; - net::MockSocket* data_; + net::SocketDataProvider* data_; int read_offset_; net::MockRead read_data_; bool need_read_data_; @@ -302,7 +304,7 @@ class MockSSLClientSocket : public MockClientSocket { net::ClientSocket* transport_socket, const std::string& hostname, const net::SSLConfig& ssl_config, - net::MockSSLSocket* socket); + net::SSLSocketDataProvider* socket); ~MockSSLClientSocket(); virtual void GetSSLInfo(net::SSLInfo* ssl_info); @@ -320,7 +322,7 @@ class MockSSLClientSocket : public MockClientSocket { class ConnectCallback; scoped_ptr<ClientSocket> transport_; - net::MockSSLSocket* data_; + net::SSLSocketDataProvider* data_; }; class TestSocketRequest : public CallbackRunner< Tuple1<int> > { diff --git a/net/socket/socks5_client_socket_unittest.cc b/net/socket/socks5_client_socket_unittest.cc index 8981ab8..d79bd02 100644 --- a/net/socket/socks5_client_socket_unittest.cc +++ b/net/socket/socks5_client_socket_unittest.cc @@ -45,7 +45,7 @@ class SOCKS5ClientSocketTest : public PlatformTest { ClientSocket* tcp_sock_; TestCompletionCallback callback_; scoped_refptr<MockHostResolver> host_resolver_; - scoped_ptr<MockSocket> mock_socket_; + scoped_ptr<SocketDataProvider> data_; private: DISALLOW_COPY_AND_ASSIGN(SOCKS5ClientSocketTest); @@ -72,8 +72,8 @@ SOCKS5ClientSocket* SOCKS5ClientSocketTest::BuildMockSocket( int port) { TestCompletionCallback callback; - mock_socket_.reset(new StaticMockSocket(reads, writes)); - tcp_sock_ = new MockTCPClientSocket(address_list_, mock_socket_.get()); + data_.reset(new StaticSocketDataProvider(reads, writes)); + tcp_sock_ = new MockTCPClientSocket(address_list_, data_.get()); int rv = tcp_sock_->Connect(&callback, NULL); EXPECT_EQ(ERR_IO_PENDING, rv); diff --git a/net/socket/socks_client_socket_unittest.cc b/net/socket/socks_client_socket_unittest.cc index 6b5c0fb..6fb7daf 100644 --- a/net/socket/socks_client_socket_unittest.cc +++ b/net/socket/socks_client_socket_unittest.cc @@ -39,7 +39,7 @@ class SOCKSClientSocketTest : public PlatformTest { ClientSocket* tcp_sock_; TestCompletionCallback callback_; scoped_refptr<MockHostResolver> host_resolver_; - scoped_ptr<MockSocket> mock_socket_; + scoped_ptr<SocketDataProvider> data_; private: DISALLOW_COPY_AND_ASSIGN(SOCKSClientSocketTest); @@ -61,8 +61,8 @@ SOCKSClientSocket* SOCKSClientSocketTest::BuildMockSocket( int port) { TestCompletionCallback callback; - mock_socket_.reset(new StaticMockSocket(reads, writes)); - tcp_sock_ = new MockTCPClientSocket(address_list_, mock_socket_.get()); + data_.reset(new StaticSocketDataProvider(reads, writes)); + tcp_sock_ = new MockTCPClientSocket(address_list_, data_.get()); int rv = tcp_sock_->Connect(&callback, NULL); EXPECT_EQ(ERR_IO_PENDING, rv); diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index 5cef70e..fa44afb 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -158,8 +158,8 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), MockRead("\r\n"), }; - StaticMockSocket data1(data_reads1, data_writes1); - mock_socket_factory.AddMockSocket(&data1); + StaticSocketDataProvider data1(data_reads1, data_writes1); + mock_socket_factory.AddSocketDataProvider(&data1); MockWrite data_writes2[] = { MockWrite("CONNECT example.com:80 HTTP/1.1\r\n" @@ -172,8 +172,8 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { MockRead("Proxy-agent: Apache/2.2.8\r\n"), MockRead("\r\n"), }; - StaticMockSocket data2(data_reads2, data_writes2); - mock_socket_factory.AddMockSocket(&data2); + StaticSocketDataProvider data2(data_reads2, data_writes2); + mock_socket_factory.AddSocketDataProvider(&data2); TestCompletionCallback callback; diff --git a/net/websockets/websocket_unittest.cc b/net/websockets/websocket_unittest.cc index b0b27df..4dbfb9e 100644 --- a/net/websockets/websocket_unittest.cc +++ b/net/websockets/websocket_unittest.cc @@ -147,8 +147,8 @@ TEST_F(WebSocketTest, Connect) { "WebSocket-Protocol: sample\r\n" "\r\n"), }; - StaticMockSocket data(data_reads, data_writes); - mock_socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + mock_socket_factory.AddSocketDataProvider(&data); WebSocket::Request* request( new WebSocket::Request(GURL("ws://example.com/demo"), @@ -207,8 +207,8 @@ TEST_F(WebSocketTest, ServerSentData) { "WebSocket-Protocol: sample\r\n" "\r\n"), }; - StaticMockSocket data(data_reads, data_writes); - mock_socket_factory.AddMockSocket(&data); + StaticSocketDataProvider data(data_reads, data_writes); + mock_socket_factory.AddSocketDataProvider(&data); WebSocket::Request* request( new WebSocket::Request(GURL("ws://example.com/demo"), |