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

Side by Side Diff: net/ftp/ftp_network_transaction_unittest.cc

Issue 149511: Refactorings surrounding HostResolver:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Merge in socks5_client_socket_unittest.cc Created 11 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 | Annotate | Revision Log
« no previous file with comments | « net/base/run_all_unittests.cc ('k') | net/http/http_network_layer_unittest.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "net/ftp/ftp_network_transaction.h" 5 #include "net/ftp/ftp_network_transaction.h"
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "net/base/host_resolver.h"
9 #include "net/base/host_resolver_unittest.h"
10 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/mock_host_resolver.h"
11 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
12 #include "net/ftp/ftp_network_session.h" 11 #include "net/ftp/ftp_network_session.h"
13 #include "net/ftp/ftp_request_info.h" 12 #include "net/ftp/ftp_request_info.h"
14 #include "net/socket/socket_test_util.h" 13 #include "net/socket/socket_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
17 16
18 namespace { 17 namespace {
19 18
20 // Size we use for IOBuffers used to receive data from the test data socket. 19 // Size we use for IOBuffers used to receive data from the test data socket.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 229 }
231 } 230 }
232 231
233 private: 232 private:
234 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadRetrFail); 233 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadRetrFail);
235 }; 234 };
236 235
237 class FtpNetworkTransactionTest : public PlatformTest { 236 class FtpNetworkTransactionTest : public PlatformTest {
238 public: 237 public:
239 FtpNetworkTransactionTest() 238 FtpNetworkTransactionTest()
240 : session_(new FtpNetworkSession(new HostResolver)), 239 : host_resolver_(new MockHostResolver),
240 session_(new FtpNetworkSession(host_resolver_)),
241 transaction_(session_.get(), &mock_socket_factory_) { 241 transaction_(session_.get(), &mock_socket_factory_) {
242 } 242 }
243 243
244 protected: 244 protected:
245 FtpRequestInfo GetRequestInfo(const std::string& url) { 245 FtpRequestInfo GetRequestInfo(const std::string& url) {
246 FtpRequestInfo info; 246 FtpRequestInfo info;
247 info.url = GURL(url); 247 info.url = GURL(url);
248 return info; 248 return info;
249 } 249 }
250 250
(...skipping 28 matching lines...) Expand all
279 void TransactionFailHelper(FtpMockControlSocket* ctrl_socket, 279 void TransactionFailHelper(FtpMockControlSocket* ctrl_socket,
280 const char* request, 280 const char* request,
281 FtpMockControlSocket::State state, 281 FtpMockControlSocket::State state,
282 FtpMockControlSocket::State next_state, 282 FtpMockControlSocket::State next_state,
283 const char* response, 283 const char* response,
284 int expected_result) { 284 int expected_result) {
285 ctrl_socket->InjectFailure(state, next_state, response); 285 ctrl_socket->InjectFailure(state, next_state, response);
286 ExecuteTransaction(ctrl_socket, request, expected_result); 286 ExecuteTransaction(ctrl_socket, request, expected_result);
287 } 287 }
288 288
289 scoped_refptr<MockHostResolver> host_resolver_;
289 scoped_refptr<FtpNetworkSession> session_; 290 scoped_refptr<FtpNetworkSession> session_;
290 MockClientSocketFactory mock_socket_factory_; 291 MockClientSocketFactory mock_socket_factory_;
291 FtpNetworkTransaction transaction_; 292 FtpNetworkTransaction transaction_;
292 TestCompletionCallback callback_; 293 TestCompletionCallback callback_;
293 }; 294 };
294 295
295 TEST_F(FtpNetworkTransactionTest, FailedLookup) { 296 TEST_F(FtpNetworkTransactionTest, FailedLookup) {
296 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); 297 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost");
297 scoped_refptr<RuleBasedHostMapper> mapper(new RuleBasedHostMapper()); 298 host_resolver_->rules()->AddSimulatedFailure("badhost");
298 mapper->AddSimulatedFailure("badhost");
299 ScopedHostMapper scoped_mapper(mapper.get());
300 ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_)); 299 ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_));
301 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult()); 300 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult());
302 } 301 }
303 302
304 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { 303 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) {
305 FtpMockControlSocketDirectoryListing ctrl_socket; 304 FtpMockControlSocketDirectoryListing ctrl_socket;
306 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); 305 ExecuteTransaction(&ctrl_socket, "ftp://host", OK);
307 } 306 }
308 307
309 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { 308 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; 540 FtpMockControlSocketFileDownloadRetrFail ctrl_socket;
542 TransactionFailHelper(&ctrl_socket, 541 TransactionFailHelper(&ctrl_socket,
543 "ftp://host/file", 542 "ftp://host/file",
544 FtpMockControlSocket::PRE_RETR, 543 FtpMockControlSocket::PRE_RETR,
545 FtpMockControlSocket::PRE_PASV2, 544 FtpMockControlSocket::PRE_PASV2,
546 "500 failed retr\r\n", 545 "500 failed retr\r\n",
547 ERR_FAILED); 546 ERR_FAILED);
548 } 547 }
549 548
550 } // namespace net 549 } // namespace net
OLDNEW
« no previous file with comments | « net/base/run_all_unittests.cc ('k') | net/http/http_network_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698