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

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 1376473003: Notify NQE of TCP RTT values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed net tests compilation issues, Added tests Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 // server, then wait for connection results. This must be called after 762 // server, then wait for connection results. This must be called after
763 // a successful StartTestServer() call. 763 // a successful StartTestServer() call.
764 // |ssl_config| the SSL configuration to use. 764 // |ssl_config| the SSL configuration to use.
765 // |result| will retrieve the ::Connect() result value. 765 // |result| will retrieve the ::Connect() result value.
766 // Returns true on success, false otherwise. Success means that the SSL socket 766 // Returns true on success, false otherwise. Success means that the SSL socket
767 // could be created and its Connect() was called, not that the connection 767 // could be created and its Connect() was called, not that the connection
768 // itself was a success. 768 // itself was a success.
769 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config, 769 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config,
770 int* result) { 770 int* result) {
771 scoped_ptr<StreamSocket> transport( 771 scoped_ptr<StreamSocket> transport(
772 new TCPClientSocket(addr_, &log_, NetLog::Source())); 772 new TCPClientSocket(addr_, NULL, &log_, NetLog::Source()));
773 int rv = callback_.GetResult(transport->Connect(callback_.callback())); 773 int rv = callback_.GetResult(transport->Connect(callback_.callback()));
774 if (rv != OK) { 774 if (rv != OK) {
775 LOG(ERROR) << "Could not connect to SpawnedTestServer"; 775 LOG(ERROR) << "Could not connect to SpawnedTestServer";
776 return false; 776 return false;
777 } 777 }
778 778
779 sock_ = CreateSSLClientSocket(std::move(transport), 779 sock_ = CreateSSLClientSocket(std::move(transport),
780 spawned_test_server_->host_port_pair(), 780 spawned_test_server_->host_port_pair(),
781 ssl_config); 781 ssl_config);
782 EXPECT_FALSE(sock_->IsConnected()); 782 EXPECT_FALSE(sock_->IsConnected());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 if (!spawned_test_server.Start()) 825 if (!spawned_test_server.Start())
826 return NULL; 826 return NULL;
827 827
828 AddressList addr; 828 AddressList addr;
829 if (!spawned_test_server.GetAddressList(&addr)) 829 if (!spawned_test_server.GetAddressList(&addr))
830 return NULL; 830 return NULL;
831 831
832 TestCompletionCallback callback; 832 TestCompletionCallback callback;
833 TestNetLog log; 833 TestNetLog log;
834 scoped_ptr<StreamSocket> transport( 834 scoped_ptr<StreamSocket> transport(
835 new TCPClientSocket(addr, &log, NetLog::Source())); 835 new TCPClientSocket(addr, NULL, &log, NetLog::Source()));
836 int rv = callback.GetResult(transport->Connect(callback.callback())); 836 int rv = callback.GetResult(transport->Connect(callback.callback()));
837 EXPECT_EQ(OK, rv); 837 EXPECT_EQ(OK, rv);
838 838
839 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 839 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
840 std::move(transport), spawned_test_server.host_port_pair(), 840 std::move(transport), spawned_test_server.host_port_pair(),
841 SSLConfig())); 841 SSLConfig()));
842 EXPECT_FALSE(sock->IsConnected()); 842 EXPECT_FALSE(sock->IsConnected());
843 843
844 rv = callback.GetResult(sock->Connect(callback.callback())); 844 rv = callback.GetResult(sock->Connect(callback.callback()));
845 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); 845 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
(...skipping 25 matching lines...) Expand all
871 // 871 //
872 // Must be called after StartTestServer is called. 872 // Must be called after StartTestServer is called.
873 void CreateAndConnectUntilServerFinishedReceived( 873 void CreateAndConnectUntilServerFinishedReceived(
874 const SSLConfig& client_config, 874 const SSLConfig& client_config,
875 TestCompletionCallback* callback, 875 TestCompletionCallback* callback,
876 FakeBlockingStreamSocket** out_raw_transport, 876 FakeBlockingStreamSocket** out_raw_transport,
877 scoped_ptr<SSLClientSocket>* out_sock) { 877 scoped_ptr<SSLClientSocket>* out_sock) {
878 CHECK(spawned_test_server()); 878 CHECK(spawned_test_server());
879 879
880 scoped_ptr<StreamSocket> real_transport( 880 scoped_ptr<StreamSocket> real_transport(
881 new TCPClientSocket(addr(), NULL, NetLog::Source())); 881 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
882 scoped_ptr<FakeBlockingStreamSocket> transport( 882 scoped_ptr<FakeBlockingStreamSocket> transport(
883 new FakeBlockingStreamSocket(std::move(real_transport))); 883 new FakeBlockingStreamSocket(std::move(real_transport)));
884 int rv = callback->GetResult(transport->Connect(callback->callback())); 884 int rv = callback->GetResult(transport->Connect(callback->callback()));
885 EXPECT_EQ(OK, rv); 885 EXPECT_EQ(OK, rv);
886 886
887 FakeBlockingStreamSocket* raw_transport = transport.get(); 887 FakeBlockingStreamSocket* raw_transport = transport.get();
888 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( 888 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket(
889 std::move(transport), spawned_test_server()->host_port_pair(), 889 std::move(transport), spawned_test_server()->host_port_pair(),
890 client_config); 890 client_config);
891 891
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 }; 990 };
991 991
992 } // namespace 992 } // namespace
993 993
994 TEST_F(SSLClientSocketTest, Connect) { 994 TEST_F(SSLClientSocketTest, Connect) {
995 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 995 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
996 996
997 TestCompletionCallback callback; 997 TestCompletionCallback callback;
998 TestNetLog log; 998 TestNetLog log;
999 scoped_ptr<StreamSocket> transport( 999 scoped_ptr<StreamSocket> transport(
1000 new TCPClientSocket(addr(), &log, NetLog::Source())); 1000 new TCPClientSocket(addr(), NULL, &log, NetLog::Source()));
1001 int rv = callback.GetResult(transport->Connect(callback.callback())); 1001 int rv = callback.GetResult(transport->Connect(callback.callback()));
1002 EXPECT_EQ(OK, rv); 1002 EXPECT_EQ(OK, rv);
1003 1003
1004 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1004 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1005 std::move(transport), spawned_test_server()->host_port_pair(), 1005 std::move(transport), spawned_test_server()->host_port_pair(),
1006 SSLConfig())); 1006 SSLConfig()));
1007 1007
1008 EXPECT_FALSE(sock->IsConnected()); 1008 EXPECT_FALSE(sock->IsConnected());
1009 1009
1010 rv = sock->Connect(callback.callback()); 1010 rv = sock->Connect(callback.callback());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 // - Server closes the underlying TCP connection directly. 1136 // - Server closes the underlying TCP connection directly.
1137 // - Server sends data unexpectedly. 1137 // - Server sends data unexpectedly.
1138 1138
1139 // Tests that the socket can be read from successfully. Also test that a peer's 1139 // Tests that the socket can be read from successfully. Also test that a peer's
1140 // close_notify alert is successfully processed without error. 1140 // close_notify alert is successfully processed without error.
1141 TEST_F(SSLClientSocketTest, Read) { 1141 TEST_F(SSLClientSocketTest, Read) {
1142 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1142 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1143 1143
1144 TestCompletionCallback callback; 1144 TestCompletionCallback callback;
1145 scoped_ptr<StreamSocket> transport( 1145 scoped_ptr<StreamSocket> transport(
1146 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1146 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1147 EXPECT_EQ(0, transport->GetTotalReceivedBytes()); 1147 EXPECT_EQ(0, transport->GetTotalReceivedBytes());
1148 1148
1149 int rv = callback.GetResult(transport->Connect(callback.callback())); 1149 int rv = callback.GetResult(transport->Connect(callback.callback()));
1150 EXPECT_EQ(OK, rv); 1150 EXPECT_EQ(OK, rv);
1151 1151
1152 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1152 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1153 std::move(transport), spawned_test_server()->host_port_pair(), 1153 std::move(transport), spawned_test_server()->host_port_pair(),
1154 SSLConfig())); 1154 SSLConfig()));
1155 EXPECT_EQ(0, sock->GetTotalReceivedBytes()); 1155 EXPECT_EQ(0, sock->GetTotalReceivedBytes());
1156 1156
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 } 1193 }
1194 1194
1195 // Tests that SSLClientSocket properly handles when the underlying transport 1195 // Tests that SSLClientSocket properly handles when the underlying transport
1196 // synchronously fails a transport read in during the handshake. The error code 1196 // synchronously fails a transport read in during the handshake. The error code
1197 // should be preserved so SSLv3 fallback logic can condition on it. 1197 // should be preserved so SSLv3 fallback logic can condition on it.
1198 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { 1198 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) {
1199 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1199 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1200 1200
1201 TestCompletionCallback callback; 1201 TestCompletionCallback callback;
1202 scoped_ptr<StreamSocket> real_transport( 1202 scoped_ptr<StreamSocket> real_transport(
1203 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1203 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1204 scoped_ptr<SynchronousErrorStreamSocket> transport( 1204 scoped_ptr<SynchronousErrorStreamSocket> transport(
1205 new SynchronousErrorStreamSocket(std::move(real_transport))); 1205 new SynchronousErrorStreamSocket(std::move(real_transport)));
1206 int rv = callback.GetResult(transport->Connect(callback.callback())); 1206 int rv = callback.GetResult(transport->Connect(callback.callback()));
1207 EXPECT_EQ(OK, rv); 1207 EXPECT_EQ(OK, rv);
1208 1208
1209 // Disable TLS False Start to avoid handshake non-determinism. 1209 // Disable TLS False Start to avoid handshake non-determinism.
1210 SSLConfig ssl_config; 1210 SSLConfig ssl_config;
1211 ssl_config.false_start_enabled = false; 1211 ssl_config.false_start_enabled = false;
1212 1212
1213 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1213 SynchronousErrorStreamSocket* raw_transport = transport.get();
(...skipping 10 matching lines...) Expand all
1224 1224
1225 // Tests that the SSLClientSocket properly handles when the underlying transport 1225 // Tests that the SSLClientSocket properly handles when the underlying transport
1226 // synchronously returns an error code - such as if an intermediary terminates 1226 // synchronously returns an error code - such as if an intermediary terminates
1227 // the socket connection uncleanly. 1227 // the socket connection uncleanly.
1228 // This is a regression test for http://crbug.com/238536 1228 // This is a regression test for http://crbug.com/238536
1229 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { 1229 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) {
1230 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1230 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1231 1231
1232 TestCompletionCallback callback; 1232 TestCompletionCallback callback;
1233 scoped_ptr<StreamSocket> real_transport( 1233 scoped_ptr<StreamSocket> real_transport(
1234 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1234 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1235 scoped_ptr<SynchronousErrorStreamSocket> transport( 1235 scoped_ptr<SynchronousErrorStreamSocket> transport(
1236 new SynchronousErrorStreamSocket(std::move(real_transport))); 1236 new SynchronousErrorStreamSocket(std::move(real_transport)));
1237 int rv = callback.GetResult(transport->Connect(callback.callback())); 1237 int rv = callback.GetResult(transport->Connect(callback.callback()));
1238 EXPECT_EQ(OK, rv); 1238 EXPECT_EQ(OK, rv);
1239 1239
1240 // Disable TLS False Start to avoid handshake non-determinism. 1240 // Disable TLS False Start to avoid handshake non-determinism.
1241 SSLConfig ssl_config; 1241 SSLConfig ssl_config;
1242 ssl_config.false_start_enabled = false; 1242 ssl_config.false_start_enabled = false;
1243 1243
1244 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1244 SynchronousErrorStreamSocket* raw_transport = transport.get();
(...skipping 29 matching lines...) Expand all
1274 1274
1275 // Tests that the SSLClientSocket properly handles when the underlying transport 1275 // Tests that the SSLClientSocket properly handles when the underlying transport
1276 // asynchronously returns an error code while writing data - such as if an 1276 // asynchronously returns an error code while writing data - such as if an
1277 // intermediary terminates the socket connection uncleanly. 1277 // intermediary terminates the socket connection uncleanly.
1278 // This is a regression test for http://crbug.com/249848 1278 // This is a regression test for http://crbug.com/249848
1279 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { 1279 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) {
1280 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1280 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1281 1281
1282 TestCompletionCallback callback; 1282 TestCompletionCallback callback;
1283 scoped_ptr<StreamSocket> real_transport( 1283 scoped_ptr<StreamSocket> real_transport(
1284 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1284 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1285 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer 1285 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer
1286 // is retained in order to configure additional errors. 1286 // is retained in order to configure additional errors.
1287 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1287 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1288 new SynchronousErrorStreamSocket(std::move(real_transport))); 1288 new SynchronousErrorStreamSocket(std::move(real_transport)));
1289 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1289 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1290 scoped_ptr<FakeBlockingStreamSocket> transport( 1290 scoped_ptr<FakeBlockingStreamSocket> transport(
1291 new FakeBlockingStreamSocket(std::move(error_socket))); 1291 new FakeBlockingStreamSocket(std::move(error_socket)));
1292 FakeBlockingStreamSocket* raw_transport = transport.get(); 1292 FakeBlockingStreamSocket* raw_transport = transport.get();
1293 int rv = callback.GetResult(transport->Connect(callback.callback())); 1293 int rv = callback.GetResult(transport->Connect(callback.callback()));
1294 EXPECT_EQ(OK, rv); 1294 EXPECT_EQ(OK, rv);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1341
1342 // If there is a Write failure at the transport with no follow-up Read, although 1342 // If there is a Write failure at the transport with no follow-up Read, although
1343 // the write error will not be returned to the client until a future Read or 1343 // the write error will not be returned to the client until a future Read or
1344 // Write operation, SSLClientSocket should not spin attempting to re-write on 1344 // Write operation, SSLClientSocket should not spin attempting to re-write on
1345 // the socket. This is a regression test for part of https://crbug.com/381160. 1345 // the socket. This is a regression test for part of https://crbug.com/381160.
1346 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) { 1346 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) {
1347 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1347 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1348 1348
1349 TestCompletionCallback callback; 1349 TestCompletionCallback callback;
1350 scoped_ptr<StreamSocket> real_transport( 1350 scoped_ptr<StreamSocket> real_transport(
1351 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1351 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1352 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer 1352 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer
1353 // is retained in order to query them. 1353 // is retained in order to query them.
1354 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1354 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1355 new SynchronousErrorStreamSocket(std::move(real_transport))); 1355 new SynchronousErrorStreamSocket(std::move(real_transport)));
1356 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1356 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1357 scoped_ptr<CountingStreamSocket> counting_socket( 1357 scoped_ptr<CountingStreamSocket> counting_socket(
1358 new CountingStreamSocket(std::move(error_socket))); 1358 new CountingStreamSocket(std::move(error_socket)));
1359 CountingStreamSocket* raw_counting_socket = counting_socket.get(); 1359 CountingStreamSocket* raw_counting_socket = counting_socket.get();
1360 int rv = callback.GetResult(counting_socket->Connect(callback.callback())); 1360 int rv = callback.GetResult(counting_socket->Connect(callback.callback()));
1361 ASSERT_EQ(OK, rv); 1361 ASSERT_EQ(OK, rv);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 // mode when the underlying transport is blocked on sending data. When the 1441 // mode when the underlying transport is blocked on sending data. When the
1442 // underlying transport completes due to an error, it should invoke both the 1442 // underlying transport completes due to an error, it should invoke both the
1443 // Read() and Write() callbacks. If the socket is deleted by the Read() 1443 // Read() and Write() callbacks. If the socket is deleted by the Read()
1444 // callback, the Write() callback should not be invoked. 1444 // callback, the Write() callback should not be invoked.
1445 // Regression test for http://crbug.com/232633 1445 // Regression test for http://crbug.com/232633
1446 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) { 1446 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) {
1447 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1447 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1448 1448
1449 TestCompletionCallback callback; 1449 TestCompletionCallback callback;
1450 scoped_ptr<StreamSocket> real_transport( 1450 scoped_ptr<StreamSocket> real_transport(
1451 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1451 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1452 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer 1452 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer
1453 // is retained in order to configure additional errors. 1453 // is retained in order to configure additional errors.
1454 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1454 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1455 new SynchronousErrorStreamSocket(std::move(real_transport))); 1455 new SynchronousErrorStreamSocket(std::move(real_transport)));
1456 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1456 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1457 scoped_ptr<FakeBlockingStreamSocket> transport( 1457 scoped_ptr<FakeBlockingStreamSocket> transport(
1458 new FakeBlockingStreamSocket(std::move(error_socket))); 1458 new FakeBlockingStreamSocket(std::move(error_socket)));
1459 FakeBlockingStreamSocket* raw_transport = transport.get(); 1459 FakeBlockingStreamSocket* raw_transport = transport.get();
1460 1460
1461 int rv = callback.GetResult(transport->Connect(callback.callback())); 1461 int rv = callback.GetResult(transport->Connect(callback.callback()));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 1550
1551 // Tests that the SSLClientSocket does not crash if data is received on the 1551 // Tests that the SSLClientSocket does not crash if data is received on the
1552 // transport socket after a failing write. This can occur if we have a Write 1552 // transport socket after a failing write. This can occur if we have a Write
1553 // error in a SPDY socket. 1553 // error in a SPDY socket.
1554 // Regression test for http://crbug.com/335557 1554 // Regression test for http://crbug.com/335557
1555 TEST_F(SSLClientSocketTest, Read_WithWriteError) { 1555 TEST_F(SSLClientSocketTest, Read_WithWriteError) {
1556 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1556 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1557 1557
1558 TestCompletionCallback callback; 1558 TestCompletionCallback callback;
1559 scoped_ptr<StreamSocket> real_transport( 1559 scoped_ptr<StreamSocket> real_transport(
1560 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1560 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1561 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer 1561 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer
1562 // is retained in order to configure additional errors. 1562 // is retained in order to configure additional errors.
1563 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1563 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1564 new SynchronousErrorStreamSocket(std::move(real_transport))); 1564 new SynchronousErrorStreamSocket(std::move(real_transport)));
1565 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1565 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1566 scoped_ptr<FakeBlockingStreamSocket> transport( 1566 scoped_ptr<FakeBlockingStreamSocket> transport(
1567 new FakeBlockingStreamSocket(std::move(error_socket))); 1567 new FakeBlockingStreamSocket(std::move(error_socket)));
1568 FakeBlockingStreamSocket* raw_transport = transport.get(); 1568 FakeBlockingStreamSocket* raw_transport = transport.get();
1569 1569
1570 int rv = callback.GetResult(transport->Connect(callback.callback())); 1570 int rv = callback.GetResult(transport->Connect(callback.callback()));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 #endif 1647 #endif
1648 } 1648 }
1649 1649
1650 // Tests that SSLClientSocket fails the handshake if the underlying 1650 // Tests that SSLClientSocket fails the handshake if the underlying
1651 // transport is cleanly closed. 1651 // transport is cleanly closed.
1652 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) { 1652 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) {
1653 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1653 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1654 1654
1655 TestCompletionCallback callback; 1655 TestCompletionCallback callback;
1656 scoped_ptr<StreamSocket> real_transport( 1656 scoped_ptr<StreamSocket> real_transport(
1657 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1657 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1658 scoped_ptr<SynchronousErrorStreamSocket> transport( 1658 scoped_ptr<SynchronousErrorStreamSocket> transport(
1659 new SynchronousErrorStreamSocket(std::move(real_transport))); 1659 new SynchronousErrorStreamSocket(std::move(real_transport)));
1660 int rv = callback.GetResult(transport->Connect(callback.callback())); 1660 int rv = callback.GetResult(transport->Connect(callback.callback()));
1661 EXPECT_EQ(OK, rv); 1661 EXPECT_EQ(OK, rv);
1662 1662
1663 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1663 SynchronousErrorStreamSocket* raw_transport = transport.get();
1664 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1664 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1665 std::move(transport), spawned_test_server()->host_port_pair(), 1665 std::move(transport), spawned_test_server()->host_port_pair(),
1666 SSLConfig())); 1666 SSLConfig()));
1667 1667
1668 raw_transport->SetNextReadError(0); 1668 raw_transport->SetNextReadError(0);
1669 1669
1670 rv = callback.GetResult(sock->Connect(callback.callback())); 1670 rv = callback.GetResult(sock->Connect(callback.callback()));
1671 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); 1671 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv);
1672 EXPECT_FALSE(sock->IsConnected()); 1672 EXPECT_FALSE(sock->IsConnected());
1673 } 1673 }
1674 1674
1675 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket 1675 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket
1676 // is cleanly closed, but the peer does not send close_notify. 1676 // is cleanly closed, but the peer does not send close_notify.
1677 // This is a regression test for https://crbug.com/422246 1677 // This is a regression test for https://crbug.com/422246
1678 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) { 1678 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) {
1679 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1679 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1680 1680
1681 TestCompletionCallback callback; 1681 TestCompletionCallback callback;
1682 scoped_ptr<StreamSocket> real_transport( 1682 scoped_ptr<StreamSocket> real_transport(
1683 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1683 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1684 scoped_ptr<SynchronousErrorStreamSocket> transport( 1684 scoped_ptr<SynchronousErrorStreamSocket> transport(
1685 new SynchronousErrorStreamSocket(std::move(real_transport))); 1685 new SynchronousErrorStreamSocket(std::move(real_transport)));
1686 int rv = callback.GetResult(transport->Connect(callback.callback())); 1686 int rv = callback.GetResult(transport->Connect(callback.callback()));
1687 EXPECT_EQ(OK, rv); 1687 EXPECT_EQ(OK, rv);
1688 1688
1689 // Disable TLS False Start to ensure the handshake has completed. 1689 // Disable TLS False Start to ensure the handshake has completed.
1690 SSLConfig ssl_config; 1690 SSLConfig ssl_config;
1691 ssl_config.false_start_enabled = false; 1691 ssl_config.false_start_enabled = false;
1692 1692
1693 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1693 SynchronousErrorStreamSocket* raw_transport = transport.get();
(...skipping 12 matching lines...) Expand all
1706 } 1706 }
1707 1707
1708 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the 1708 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the
1709 // underlying socket is cleanly closed asynchronously. 1709 // underlying socket is cleanly closed asynchronously.
1710 // This is a regression test for https://crbug.com/422246 1710 // This is a regression test for https://crbug.com/422246
1711 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) { 1711 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) {
1712 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1712 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1713 1713
1714 TestCompletionCallback callback; 1714 TestCompletionCallback callback;
1715 scoped_ptr<StreamSocket> real_transport( 1715 scoped_ptr<StreamSocket> real_transport(
1716 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1716 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1717 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1717 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1718 new SynchronousErrorStreamSocket(std::move(real_transport))); 1718 new SynchronousErrorStreamSocket(std::move(real_transport)));
1719 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1719 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1720 scoped_ptr<FakeBlockingStreamSocket> transport( 1720 scoped_ptr<FakeBlockingStreamSocket> transport(
1721 new FakeBlockingStreamSocket(std::move(error_socket))); 1721 new FakeBlockingStreamSocket(std::move(error_socket)));
1722 FakeBlockingStreamSocket* raw_transport = transport.get(); 1722 FakeBlockingStreamSocket* raw_transport = transport.get();
1723 int rv = callback.GetResult(transport->Connect(callback.callback())); 1723 int rv = callback.GetResult(transport->Connect(callback.callback()));
1724 EXPECT_EQ(OK, rv); 1724 EXPECT_EQ(OK, rv);
1725 1725
1726 // Disable TLS False Start to ensure the handshake has completed. 1726 // Disable TLS False Start to ensure the handshake has completed.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 EXPECT_GE(rv, 0); 1787 EXPECT_GE(rv, 0);
1788 } while (rv > 0); 1788 } while (rv > 0);
1789 } 1789 }
1790 1790
1791 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) { 1791 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) {
1792 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1792 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1793 1793
1794 TestCompletionCallback callback; 1794 TestCompletionCallback callback;
1795 1795
1796 scoped_ptr<StreamSocket> real_transport( 1796 scoped_ptr<StreamSocket> real_transport(
1797 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1797 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1798 scoped_ptr<ReadBufferingStreamSocket> transport( 1798 scoped_ptr<ReadBufferingStreamSocket> transport(
1799 new ReadBufferingStreamSocket(std::move(real_transport))); 1799 new ReadBufferingStreamSocket(std::move(real_transport)));
1800 ReadBufferingStreamSocket* raw_transport = transport.get(); 1800 ReadBufferingStreamSocket* raw_transport = transport.get();
1801 int rv = callback.GetResult(transport->Connect(callback.callback())); 1801 int rv = callback.GetResult(transport->Connect(callback.callback()));
1802 ASSERT_EQ(OK, rv); 1802 ASSERT_EQ(OK, rv);
1803 1803
1804 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1804 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1805 std::move(transport), spawned_test_server()->host_port_pair(), 1805 std::move(transport), spawned_test_server()->host_port_pair(),
1806 SSLConfig())); 1806 SSLConfig()));
1807 1807
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 EXPECT_GT(rv, 0); 1858 EXPECT_GT(rv, 0);
1859 } 1859 }
1860 1860
1861 TEST_F(SSLClientSocketTest, Read_FullLogging) { 1861 TEST_F(SSLClientSocketTest, Read_FullLogging) {
1862 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1862 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1863 1863
1864 TestCompletionCallback callback; 1864 TestCompletionCallback callback;
1865 TestNetLog log; 1865 TestNetLog log;
1866 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); 1866 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes());
1867 scoped_ptr<StreamSocket> transport( 1867 scoped_ptr<StreamSocket> transport(
1868 new TCPClientSocket(addr(), &log, NetLog::Source())); 1868 new TCPClientSocket(addr(), NULL, &log, NetLog::Source()));
1869 int rv = callback.GetResult(transport->Connect(callback.callback())); 1869 int rv = callback.GetResult(transport->Connect(callback.callback()));
1870 EXPECT_EQ(OK, rv); 1870 EXPECT_EQ(OK, rv);
1871 1871
1872 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1872 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1873 std::move(transport), spawned_test_server()->host_port_pair(), 1873 std::move(transport), spawned_test_server()->host_port_pair(),
1874 SSLConfig())); 1874 SSLConfig()));
1875 1875
1876 rv = callback.GetResult(sock->Connect(callback.callback())); 1876 rv = callback.GetResult(sock->Connect(callback.callback()));
1877 EXPECT_EQ(OK, rv); 1877 EXPECT_EQ(OK, rv);
1878 EXPECT_TRUE(sock->IsConnected()); 1878 EXPECT_TRUE(sock->IsConnected());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 1972
1973 // When creating an SSLClientSocket, it is allowed to pass in a 1973 // When creating an SSLClientSocket, it is allowed to pass in a
1974 // ClientSocketHandle that is not obtained from a client socket pool. 1974 // ClientSocketHandle that is not obtained from a client socket pool.
1975 // Here we verify that such a simple ClientSocketHandle, not associated with any 1975 // Here we verify that such a simple ClientSocketHandle, not associated with any
1976 // client socket pool, can be destroyed safely. 1976 // client socket pool, can be destroyed safely.
1977 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { 1977 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) {
1978 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1978 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1979 1979
1980 TestCompletionCallback callback; 1980 TestCompletionCallback callback;
1981 scoped_ptr<StreamSocket> transport( 1981 scoped_ptr<StreamSocket> transport(
1982 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1982 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1983 int rv = callback.GetResult(transport->Connect(callback.callback())); 1983 int rv = callback.GetResult(transport->Connect(callback.callback()));
1984 EXPECT_EQ(OK, rv); 1984 EXPECT_EQ(OK, rv);
1985 1985
1986 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle()); 1986 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle());
1987 socket_handle->SetSocket(std::move(transport)); 1987 socket_handle->SetSocket(std::move(transport));
1988 1988
1989 scoped_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket( 1989 scoped_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket(
1990 std::move(socket_handle), spawned_test_server()->host_port_pair(), 1990 std::move(socket_handle), spawned_test_server()->host_port_pair(),
1991 SSLConfig(), context_)); 1991 SSLConfig(), context_));
1992 1992
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 } 2493 }
2494 2494
2495 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't 2495 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't
2496 // been flushed completely out of SSLClientSocket's internal buffers. This is a 2496 // been flushed completely out of SSLClientSocket's internal buffers. This is a
2497 // regression test for https://crbug.com/466147. 2497 // regression test for https://crbug.com/466147.
2498 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { 2498 TEST_F(SSLClientSocketTest, ReusableAfterWrite) {
2499 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 2499 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
2500 2500
2501 TestCompletionCallback callback; 2501 TestCompletionCallback callback;
2502 scoped_ptr<StreamSocket> real_transport( 2502 scoped_ptr<StreamSocket> real_transport(
2503 new TCPClientSocket(addr(), NULL, NetLog::Source())); 2503 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
2504 scoped_ptr<FakeBlockingStreamSocket> transport( 2504 scoped_ptr<FakeBlockingStreamSocket> transport(
2505 new FakeBlockingStreamSocket(std::move(real_transport))); 2505 new FakeBlockingStreamSocket(std::move(real_transport)));
2506 FakeBlockingStreamSocket* raw_transport = transport.get(); 2506 FakeBlockingStreamSocket* raw_transport = transport.get();
2507 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); 2507 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback())));
2508 2508
2509 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 2509 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
2510 std::move(transport), spawned_test_server()->host_port_pair(), 2510 std::move(transport), spawned_test_server()->host_port_pair(),
2511 SSLConfig())); 2511 SSLConfig()));
2512 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); 2512 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback())));
2513 2513
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 2549
2550 // The next connection should resume. 2550 // The next connection should resume.
2551 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 2551 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2552 ASSERT_EQ(OK, rv); 2552 ASSERT_EQ(OK, rv);
2553 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 2553 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
2554 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); 2554 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type);
2555 sock_.reset(); 2555 sock_.reset();
2556 2556
2557 // Using a different HostPortPair uses a different session cache key. 2557 // Using a different HostPortPair uses a different session cache key.
2558 scoped_ptr<StreamSocket> transport( 2558 scoped_ptr<StreamSocket> transport(
2559 new TCPClientSocket(addr(), &log_, NetLog::Source())); 2559 new TCPClientSocket(addr(), NULL, &log_, NetLog::Source()));
2560 TestCompletionCallback callback; 2560 TestCompletionCallback callback;
2561 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); 2561 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback())));
2562 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( 2562 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket(
2563 std::move(transport), HostPortPair("example.com", 443), ssl_config); 2563 std::move(transport), HostPortPair("example.com", 443), ssl_config);
2564 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); 2564 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback())));
2565 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); 2565 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info));
2566 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); 2566 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2567 sock.reset(); 2567 sock.reset();
2568 2568
2569 SSLClientSocket::ClearSessionCache(); 2569 SSLClientSocket::ClearSessionCache();
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
3353 SSLInfo ssl_info; 3353 SSLInfo ssl_info;
3354 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 3354 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
3355 EXPECT_TRUE(ssl_info.client_cert_sent); 3355 EXPECT_TRUE(ssl_info.client_cert_sent);
3356 3356
3357 sock_->Disconnect(); 3357 sock_->Disconnect();
3358 EXPECT_FALSE(sock_->IsConnected()); 3358 EXPECT_FALSE(sock_->IsConnected());
3359 } 3359 }
3360 #endif // defined(USE_OPENSSL) 3360 #endif // defined(USE_OPENSSL)
3361 3361
3362 } // namespace net 3362 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698