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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 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
« no previous file with comments | « net/ftp/ftp_ctrl_response_buffer_unittest.cc ('k') | net/http/bidirectional_stream_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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/ftp/ftp_network_transaction.h" 5 #include "net/ftp/ftp_network_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/base/test_completion_callback.h" 16 #include "net/base/test_completion_callback.h"
17 #include "net/dns/mock_host_resolver.h" 17 #include "net/dns/mock_host_resolver.h"
18 #include "net/ftp/ftp_request_info.h" 18 #include "net/ftp/ftp_request_info.h"
19 #include "net/socket/socket_test_util.h" 19 #include "net/socket/socket_test_util.h"
20 #include "net/test/gtest_util.h"
21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
22 24
25 using net::test::IsError;
26 using net::test::IsOk;
27
23 namespace { 28 namespace {
24 29
25 // Size we use for IOBuffers used to receive data from the test data socket. 30 // Size we use for IOBuffers used to receive data from the test data socket.
26 const int kBufferSize = 128; 31 const int kBufferSize = 128;
27 32
28 } // namespace 33 } // namespace
29 34
30 namespace net { 35 namespace net {
31 36
32 class FtpSocketDataProvider : public SocketDataProvider { 37 class FtpSocketDataProvider : public SocketDataProvider {
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); 943 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost");
939 scoped_refptr<RuleBasedHostResolverProc> rules( 944 scoped_refptr<RuleBasedHostResolverProc> rules(
940 new RuleBasedHostResolverProc(NULL)); 945 new RuleBasedHostResolverProc(NULL));
941 rules->AddSimulatedFailure("badhost"); 946 rules->AddSimulatedFailure("badhost");
942 host_resolver_->set_rules(rules.get()); 947 host_resolver_->set_rules(rules.get());
943 948
944 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); 949 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState());
945 ASSERT_EQ(ERR_IO_PENDING, 950 ASSERT_EQ(ERR_IO_PENDING,
946 transaction_.Start(&request_info, callback_.callback(), 951 transaction_.Start(&request_info, callback_.callback(),
947 BoundNetLog())); 952 BoundNetLog()));
948 ASSERT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); 953 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED));
949 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); 954 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState());
950 } 955 }
951 956
952 // Check that when determining the host, the square brackets decorating IPv6 957 // Check that when determining the host, the square brackets decorating IPv6
953 // literals in URLs are stripped. 958 // literals in URLs are stripped.
954 TEST_P(FtpNetworkTransactionTest, StripBracketsFromIPv6Literals) { 959 TEST_P(FtpNetworkTransactionTest, StripBracketsFromIPv6Literals) {
955 // This test only makes sense for IPv6 connections. 960 // This test only makes sense for IPv6 connections.
956 if (GetFamily() != AF_INET6) 961 if (GetFamily() != AF_INET6)
957 return; 962 return;
958 963
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 NULL, 0); 1174 NULL, 0);
1170 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); 1175 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket);
1171 mock_socket_factory_.AddSocketDataProvider(&data_socket1); 1176 mock_socket_factory_.AddSocketDataProvider(&data_socket1);
1172 mock_socket_factory_.AddSocketDataProvider(&data_socket2); 1177 mock_socket_factory_.AddSocketDataProvider(&data_socket2);
1173 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); 1178 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file");
1174 1179
1175 // Start the transaction. 1180 // Start the transaction.
1176 ASSERT_EQ(ERR_IO_PENDING, 1181 ASSERT_EQ(ERR_IO_PENDING,
1177 transaction_.Start(&request_info, callback_.callback(), 1182 transaction_.Start(&request_info, callback_.callback(),
1178 BoundNetLog())); 1183 BoundNetLog()));
1179 ASSERT_EQ(OK, callback_.WaitForResult()); 1184 ASSERT_THAT(callback_.WaitForResult(), IsOk());
1180 1185
1181 // The transaction fires the callback when we can start reading data. That 1186 // The transaction fires the callback when we can start reading data. That
1182 // means that the data socket should be open. 1187 // means that the data socket should be open.
1183 MockTCPClientSocket* data_socket = 1188 MockTCPClientSocket* data_socket =
1184 static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get()); 1189 static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get());
1185 ASSERT_TRUE(data_socket); 1190 ASSERT_TRUE(data_socket);
1186 ASSERT_TRUE(data_socket->IsConnected()); 1191 ASSERT_TRUE(data_socket->IsConnected());
1187 1192
1188 // Even if the PASV response specified some other address, we connect 1193 // Even if the PASV response specified some other address, we connect
1189 // to the address we used for control connection (which could be 127.0.0.1 1194 // to the address we used for control connection (which could be 127.0.0.1
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, 1359 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD,
1355 FtpSocketDataProvider::PRE_QUIT, 1360 FtpSocketDataProvider::PRE_QUIT,
1356 "530 Login authentication failed\r\n"); 1361 "530 Login authentication failed\r\n");
1357 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); 1362 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1);
1358 1363
1359 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); 1364 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file");
1360 1365
1361 ASSERT_EQ(ERR_IO_PENDING, 1366 ASSERT_EQ(ERR_IO_PENDING,
1362 transaction_.Start(&request_info, callback_.callback(), 1367 transaction_.Start(&request_info, callback_.callback(),
1363 BoundNetLog())); 1368 BoundNetLog()));
1364 ASSERT_EQ(ERR_FTP_FAILED, callback_.WaitForResult()); 1369 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_FTP_FAILED));
1365 1370
1366 MockRead ctrl_reads[] = { 1371 MockRead ctrl_reads[] = {
1367 MockRead("220 host TestFTPd\r\n"), 1372 MockRead("220 host TestFTPd\r\n"),
1368 MockRead("221 Goodbye!\r\n"), 1373 MockRead("221 Goodbye!\r\n"),
1369 MockRead(SYNCHRONOUS, OK), 1374 MockRead(SYNCHRONOUS, OK),
1370 }; 1375 };
1371 MockWrite ctrl_writes[] = { 1376 MockWrite ctrl_writes[] = {
1372 MockWrite("QUIT\r\n"), 1377 MockWrite("QUIT\r\n"),
1373 }; 1378 };
1374 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), 1379 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads),
1375 ctrl_writes, arraysize(ctrl_writes)); 1380 ctrl_writes, arraysize(ctrl_writes));
1376 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); 1381 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2);
1377 ASSERT_EQ(ERR_IO_PENDING, 1382 ASSERT_EQ(ERR_IO_PENDING,
1378 transaction_.RestartWithAuth( 1383 transaction_.RestartWithAuth(
1379 AuthCredentials( 1384 AuthCredentials(
1380 base::ASCIIToUTF16("foo\nownz0red"), 1385 base::ASCIIToUTF16("foo\nownz0red"),
1381 base::ASCIIToUTF16("innocent")), 1386 base::ASCIIToUTF16("innocent")),
1382 callback_.callback())); 1387 callback_.callback()));
1383 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); 1388 EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_MALFORMED_IDENTITY));
1384 } 1389 }
1385 1390
1386 TEST_P(FtpNetworkTransactionTest, EvilRestartPassword) { 1391 TEST_P(FtpNetworkTransactionTest, EvilRestartPassword) {
1387 FtpSocketDataProvider ctrl_socket1; 1392 FtpSocketDataProvider ctrl_socket1;
1388 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, 1393 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD,
1389 FtpSocketDataProvider::PRE_QUIT, 1394 FtpSocketDataProvider::PRE_QUIT,
1390 "530 Login authentication failed\r\n"); 1395 "530 Login authentication failed\r\n");
1391 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); 1396 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1);
1392 1397
1393 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); 1398 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file");
1394 1399
1395 ASSERT_EQ(ERR_IO_PENDING, 1400 ASSERT_EQ(ERR_IO_PENDING,
1396 transaction_.Start(&request_info, callback_.callback(), 1401 transaction_.Start(&request_info, callback_.callback(),
1397 BoundNetLog())); 1402 BoundNetLog()));
1398 ASSERT_EQ(ERR_FTP_FAILED, callback_.WaitForResult()); 1403 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_FTP_FAILED));
1399 1404
1400 MockRead ctrl_reads[] = { 1405 MockRead ctrl_reads[] = {
1401 MockRead("220 host TestFTPd\r\n"), 1406 MockRead("220 host TestFTPd\r\n"),
1402 MockRead("331 User okay, send password\r\n"), 1407 MockRead("331 User okay, send password\r\n"),
1403 MockRead("221 Goodbye!\r\n"), 1408 MockRead("221 Goodbye!\r\n"),
1404 MockRead(SYNCHRONOUS, OK), 1409 MockRead(SYNCHRONOUS, OK),
1405 }; 1410 };
1406 MockWrite ctrl_writes[] = { 1411 MockWrite ctrl_writes[] = {
1407 MockWrite("USER innocent\r\n"), 1412 MockWrite("USER innocent\r\n"),
1408 MockWrite("QUIT\r\n"), 1413 MockWrite("QUIT\r\n"),
1409 }; 1414 };
1410 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), 1415 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads),
1411 ctrl_writes, arraysize(ctrl_writes)); 1416 ctrl_writes, arraysize(ctrl_writes));
1412 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); 1417 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2);
1413 ASSERT_EQ(ERR_IO_PENDING, 1418 ASSERT_EQ(ERR_IO_PENDING,
1414 transaction_.RestartWithAuth( 1419 transaction_.RestartWithAuth(
1415 AuthCredentials(base::ASCIIToUTF16("innocent"), 1420 AuthCredentials(base::ASCIIToUTF16("innocent"),
1416 base::ASCIIToUTF16("foo\nownz0red")), 1421 base::ASCIIToUTF16("foo\nownz0red")),
1417 callback_.callback())); 1422 callback_.callback()));
1418 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); 1423 EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_MALFORMED_IDENTITY));
1419 } 1424 }
1420 1425
1421 TEST_P(FtpNetworkTransactionTest, Escaping) { 1426 TEST_P(FtpNetworkTransactionTest, Escaping) {
1422 FtpSocketDataProviderEscaping ctrl_socket; 1427 FtpSocketDataProviderEscaping ctrl_socket;
1423 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", 1428 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81",
1424 OK); 1429 OK);
1425 } 1430 }
1426 1431
1427 // Test for http://crbug.com/23794. 1432 // Test for http://crbug.com/23794.
1428 TEST_P(FtpNetworkTransactionTest, DownloadTransactionEvilSize) { 1433 TEST_P(FtpNetworkTransactionTest, DownloadTransactionEvilSize) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 FtpSocketDataProvider::PRE_TYPE, 1658 FtpSocketDataProvider::PRE_TYPE,
1654 "257 \"\"\r\n", 1659 "257 \"\"\r\n",
1655 OK); 1660 OK);
1656 } 1661 }
1657 1662
1658 INSTANTIATE_TEST_CASE_P(FTP, 1663 INSTANTIATE_TEST_CASE_P(FTP,
1659 FtpNetworkTransactionTest, 1664 FtpNetworkTransactionTest,
1660 ::testing::Values(AF_INET, AF_INET6)); 1665 ::testing::Values(AF_INET, AF_INET6));
1661 1666
1662 } // namespace net 1667 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_ctrl_response_buffer_unittest.cc ('k') | net/http/bidirectional_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698