OLD | NEW |
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" |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 }; | 890 }; |
891 | 891 |
892 std::unique_ptr<StaticSocketDataProvider> data_socket( | 892 std::unique_ptr<StaticSocketDataProvider> data_socket( |
893 new StaticSocketDataProvider(data_reads, arraysize(data_reads), NULL, | 893 new StaticSocketDataProvider(data_reads, arraysize(data_reads), NULL, |
894 0)); | 894 0)); |
895 mock_socket_factory_.AddSocketDataProvider(data_socket.get()); | 895 mock_socket_factory_.AddSocketDataProvider(data_socket.get()); |
896 FtpRequestInfo request_info = GetRequestInfo(request); | 896 FtpRequestInfo request_info = GetRequestInfo(request); |
897 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 897 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
898 ASSERT_EQ(ERR_IO_PENDING, | 898 ASSERT_EQ(ERR_IO_PENDING, |
899 transaction_.Start(&request_info, callback_.callback(), | 899 transaction_.Start(&request_info, callback_.callback(), |
900 BoundNetLog())); | 900 NetLogWithSource())); |
901 EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 901 EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
902 ASSERT_EQ(expected_result, callback_.WaitForResult()); | 902 ASSERT_EQ(expected_result, callback_.WaitForResult()); |
903 if (expected_result == OK) { | 903 if (expected_result == OK) { |
904 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); | 904 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); |
905 memset(io_buffer->data(), 0, kBufferSize); | 905 memset(io_buffer->data(), 0, kBufferSize); |
906 ASSERT_EQ(ERR_IO_PENDING, | 906 ASSERT_EQ(ERR_IO_PENDING, |
907 transaction_.Read(io_buffer.get(), kBufferSize, | 907 transaction_.Read(io_buffer.get(), kBufferSize, |
908 callback_.callback())); | 908 callback_.callback())); |
909 ASSERT_EQ(static_cast<int>(mock_data.length()), | 909 ASSERT_EQ(static_cast<int>(mock_data.length()), |
910 callback_.WaitForResult()); | 910 callback_.WaitForResult()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 TEST_P(FtpNetworkTransactionTest, FailedLookup) { | 942 TEST_P(FtpNetworkTransactionTest, FailedLookup) { |
943 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); | 943 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); |
944 scoped_refptr<RuleBasedHostResolverProc> rules( | 944 scoped_refptr<RuleBasedHostResolverProc> rules( |
945 new RuleBasedHostResolverProc(NULL)); | 945 new RuleBasedHostResolverProc(NULL)); |
946 rules->AddSimulatedFailure("badhost"); | 946 rules->AddSimulatedFailure("badhost"); |
947 host_resolver_->set_rules(rules.get()); | 947 host_resolver_->set_rules(rules.get()); |
948 | 948 |
949 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 949 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
950 ASSERT_EQ(ERR_IO_PENDING, | 950 ASSERT_EQ(ERR_IO_PENDING, |
951 transaction_.Start(&request_info, callback_.callback(), | 951 transaction_.Start(&request_info, callback_.callback(), |
952 BoundNetLog())); | 952 NetLogWithSource())); |
953 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); | 953 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
954 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 954 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
955 } | 955 } |
956 | 956 |
957 // Check that when determining the host, the square brackets decorating IPv6 | 957 // Check that when determining the host, the square brackets decorating IPv6 |
958 // literals in URLs are stripped. | 958 // literals in URLs are stripped. |
959 TEST_P(FtpNetworkTransactionTest, StripBracketsFromIPv6Literals) { | 959 TEST_P(FtpNetworkTransactionTest, StripBracketsFromIPv6Literals) { |
960 // This test only makes sense for IPv6 connections. | 960 // This test only makes sense for IPv6 connections. |
961 if (GetFamily() != AF_INET6) | 961 if (GetFamily() != AF_INET6) |
962 return; | 962 return; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 StaticSocketDataProvider data_socket2(data_reads, arraysize(data_reads), | 1173 StaticSocketDataProvider data_socket2(data_reads, arraysize(data_reads), |
1174 NULL, 0); | 1174 NULL, 0); |
1175 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); | 1175 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); |
1176 mock_socket_factory_.AddSocketDataProvider(&data_socket1); | 1176 mock_socket_factory_.AddSocketDataProvider(&data_socket1); |
1177 mock_socket_factory_.AddSocketDataProvider(&data_socket2); | 1177 mock_socket_factory_.AddSocketDataProvider(&data_socket2); |
1178 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); | 1178 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); |
1179 | 1179 |
1180 // Start the transaction. | 1180 // Start the transaction. |
1181 ASSERT_EQ(ERR_IO_PENDING, | 1181 ASSERT_EQ(ERR_IO_PENDING, |
1182 transaction_.Start(&request_info, callback_.callback(), | 1182 transaction_.Start(&request_info, callback_.callback(), |
1183 BoundNetLog())); | 1183 NetLogWithSource())); |
1184 ASSERT_THAT(callback_.WaitForResult(), IsOk()); | 1184 ASSERT_THAT(callback_.WaitForResult(), IsOk()); |
1185 | 1185 |
1186 // 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 |
1187 // means that the data socket should be open. | 1187 // means that the data socket should be open. |
1188 MockTCPClientSocket* data_socket = | 1188 MockTCPClientSocket* data_socket = |
1189 static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get()); | 1189 static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get()); |
1190 ASSERT_TRUE(data_socket); | 1190 ASSERT_TRUE(data_socket); |
1191 ASSERT_TRUE(data_socket->IsConnected()); | 1191 ASSERT_TRUE(data_socket->IsConnected()); |
1192 | 1192 |
1193 // Even if the PASV response specified some other address, we connect | 1193 // Even if the PASV response specified some other address, we connect |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 FtpSocketDataProvider ctrl_socket1; | 1358 FtpSocketDataProvider ctrl_socket1; |
1359 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, | 1359 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, |
1360 FtpSocketDataProvider::PRE_QUIT, | 1360 FtpSocketDataProvider::PRE_QUIT, |
1361 "530 Login authentication failed\r\n"); | 1361 "530 Login authentication failed\r\n"); |
1362 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); | 1362 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); |
1363 | 1363 |
1364 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); | 1364 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); |
1365 | 1365 |
1366 ASSERT_EQ(ERR_IO_PENDING, | 1366 ASSERT_EQ(ERR_IO_PENDING, |
1367 transaction_.Start(&request_info, callback_.callback(), | 1367 transaction_.Start(&request_info, callback_.callback(), |
1368 BoundNetLog())); | 1368 NetLogWithSource())); |
1369 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_FTP_FAILED)); | 1369 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_FTP_FAILED)); |
1370 | 1370 |
1371 MockRead ctrl_reads[] = { | 1371 MockRead ctrl_reads[] = { |
1372 MockRead("220 host TestFTPd\r\n"), | 1372 MockRead("220 host TestFTPd\r\n"), |
1373 MockRead("221 Goodbye!\r\n"), | 1373 MockRead("221 Goodbye!\r\n"), |
1374 MockRead(SYNCHRONOUS, OK), | 1374 MockRead(SYNCHRONOUS, OK), |
1375 }; | 1375 }; |
1376 MockWrite ctrl_writes[] = { | 1376 MockWrite ctrl_writes[] = { |
1377 MockWrite("QUIT\r\n"), | 1377 MockWrite("QUIT\r\n"), |
1378 }; | 1378 }; |
(...skipping 13 matching lines...) Expand all Loading... |
1392 FtpSocketDataProvider ctrl_socket1; | 1392 FtpSocketDataProvider ctrl_socket1; |
1393 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, | 1393 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, |
1394 FtpSocketDataProvider::PRE_QUIT, | 1394 FtpSocketDataProvider::PRE_QUIT, |
1395 "530 Login authentication failed\r\n"); | 1395 "530 Login authentication failed\r\n"); |
1396 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); | 1396 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); |
1397 | 1397 |
1398 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); | 1398 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); |
1399 | 1399 |
1400 ASSERT_EQ(ERR_IO_PENDING, | 1400 ASSERT_EQ(ERR_IO_PENDING, |
1401 transaction_.Start(&request_info, callback_.callback(), | 1401 transaction_.Start(&request_info, callback_.callback(), |
1402 BoundNetLog())); | 1402 NetLogWithSource())); |
1403 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_FTP_FAILED)); | 1403 ASSERT_THAT(callback_.WaitForResult(), IsError(ERR_FTP_FAILED)); |
1404 | 1404 |
1405 MockRead ctrl_reads[] = { | 1405 MockRead ctrl_reads[] = { |
1406 MockRead("220 host TestFTPd\r\n"), | 1406 MockRead("220 host TestFTPd\r\n"), |
1407 MockRead("331 User okay, send password\r\n"), | 1407 MockRead("331 User okay, send password\r\n"), |
1408 MockRead("221 Goodbye!\r\n"), | 1408 MockRead("221 Goodbye!\r\n"), |
1409 MockRead(SYNCHRONOUS, OK), | 1409 MockRead(SYNCHRONOUS, OK), |
1410 }; | 1410 }; |
1411 MockWrite ctrl_writes[] = { | 1411 MockWrite ctrl_writes[] = { |
1412 MockWrite("USER innocent\r\n"), | 1412 MockWrite("USER innocent\r\n"), |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 FtpSocketDataProvider::PRE_TYPE, | 1658 FtpSocketDataProvider::PRE_TYPE, |
1659 "257 \"\"\r\n", | 1659 "257 \"\"\r\n", |
1660 OK); | 1660 OK); |
1661 } | 1661 } |
1662 | 1662 |
1663 INSTANTIATE_TEST_CASE_P(FTP, | 1663 INSTANTIATE_TEST_CASE_P(FTP, |
1664 FtpNetworkTransactionTest, | 1664 FtpNetworkTransactionTest, |
1665 ::testing::Values(AF_INET, AF_INET6)); | 1665 ::testing::Values(AF_INET, AF_INET6)); |
1666 | 1666 |
1667 } // namespace net | 1667 } // namespace net |
OLD | NEW |