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

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: Added throttle on TCP socket notifications (with tests) Created 4 years, 8 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 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 // server, then wait for connection results. This must be called after 766 // server, then wait for connection results. This must be called after
767 // a successful StartTestServer() call. 767 // a successful StartTestServer() call.
768 // |ssl_config| the SSL configuration to use. 768 // |ssl_config| the SSL configuration to use.
769 // |result| will retrieve the ::Connect() result value. 769 // |result| will retrieve the ::Connect() result value.
770 // Returns true on success, false otherwise. Success means that the SSL socket 770 // Returns true on success, false otherwise. Success means that the SSL socket
771 // could be created and its Connect() was called, not that the connection 771 // could be created and its Connect() was called, not that the connection
772 // itself was a success. 772 // itself was a success.
773 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config, 773 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config,
774 int* result) { 774 int* result) {
775 scoped_ptr<StreamSocket> transport( 775 scoped_ptr<StreamSocket> transport(
776 new TCPClientSocket(addr_, &log_, NetLog::Source())); 776 new TCPClientSocket(addr_, NULL, &log_, NetLog::Source()));
777 int rv = callback_.GetResult(transport->Connect(callback_.callback())); 777 int rv = callback_.GetResult(transport->Connect(callback_.callback()));
778 if (rv != OK) { 778 if (rv != OK) {
779 LOG(ERROR) << "Could not connect to SpawnedTestServer"; 779 LOG(ERROR) << "Could not connect to SpawnedTestServer";
780 return false; 780 return false;
781 } 781 }
782 782
783 sock_ = CreateSSLClientSocket(std::move(transport), 783 sock_ = CreateSSLClientSocket(std::move(transport),
784 spawned_test_server_->host_port_pair(), 784 spawned_test_server_->host_port_pair(),
785 ssl_config); 785 ssl_config);
786 EXPECT_FALSE(sock_->IsConnected()); 786 EXPECT_FALSE(sock_->IsConnected());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 if (!spawned_test_server.Start()) 829 if (!spawned_test_server.Start())
830 return NULL; 830 return NULL;
831 831
832 AddressList addr; 832 AddressList addr;
833 if (!spawned_test_server.GetAddressList(&addr)) 833 if (!spawned_test_server.GetAddressList(&addr))
834 return NULL; 834 return NULL;
835 835
836 TestCompletionCallback callback; 836 TestCompletionCallback callback;
837 TestNetLog log; 837 TestNetLog log;
838 scoped_ptr<StreamSocket> transport( 838 scoped_ptr<StreamSocket> transport(
839 new TCPClientSocket(addr, &log, NetLog::Source())); 839 new TCPClientSocket(addr, NULL, &log, NetLog::Source()));
840 int rv = callback.GetResult(transport->Connect(callback.callback())); 840 int rv = callback.GetResult(transport->Connect(callback.callback()));
841 EXPECT_EQ(OK, rv); 841 EXPECT_EQ(OK, rv);
842 842
843 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 843 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
844 std::move(transport), spawned_test_server.host_port_pair(), 844 std::move(transport), spawned_test_server.host_port_pair(),
845 SSLConfig())); 845 SSLConfig()));
846 EXPECT_FALSE(sock->IsConnected()); 846 EXPECT_FALSE(sock->IsConnected());
847 847
848 rv = callback.GetResult(sock->Connect(callback.callback())); 848 rv = callback.GetResult(sock->Connect(callback.callback()));
849 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); 849 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
(...skipping 25 matching lines...) Expand all
875 // 875 //
876 // Must be called after StartTestServer is called. 876 // Must be called after StartTestServer is called.
877 void CreateAndConnectUntilServerFinishedReceived( 877 void CreateAndConnectUntilServerFinishedReceived(
878 const SSLConfig& client_config, 878 const SSLConfig& client_config,
879 TestCompletionCallback* callback, 879 TestCompletionCallback* callback,
880 FakeBlockingStreamSocket** out_raw_transport, 880 FakeBlockingStreamSocket** out_raw_transport,
881 scoped_ptr<SSLClientSocket>* out_sock) { 881 scoped_ptr<SSLClientSocket>* out_sock) {
882 CHECK(spawned_test_server()); 882 CHECK(spawned_test_server());
883 883
884 scoped_ptr<StreamSocket> real_transport( 884 scoped_ptr<StreamSocket> real_transport(
885 new TCPClientSocket(addr(), NULL, NetLog::Source())); 885 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
886 scoped_ptr<FakeBlockingStreamSocket> transport( 886 scoped_ptr<FakeBlockingStreamSocket> transport(
887 new FakeBlockingStreamSocket(std::move(real_transport))); 887 new FakeBlockingStreamSocket(std::move(real_transport)));
888 int rv = callback->GetResult(transport->Connect(callback->callback())); 888 int rv = callback->GetResult(transport->Connect(callback->callback()));
889 EXPECT_EQ(OK, rv); 889 EXPECT_EQ(OK, rv);
890 890
891 FakeBlockingStreamSocket* raw_transport = transport.get(); 891 FakeBlockingStreamSocket* raw_transport = transport.get();
892 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( 892 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket(
893 std::move(transport), spawned_test_server()->host_port_pair(), 893 std::move(transport), spawned_test_server()->host_port_pair(),
894 client_config); 894 client_config);
895 895
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 }; 994 };
995 995
996 } // namespace 996 } // namespace
997 997
998 TEST_F(SSLClientSocketTest, Connect) { 998 TEST_F(SSLClientSocketTest, Connect) {
999 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 999 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1000 1000
1001 TestCompletionCallback callback; 1001 TestCompletionCallback callback;
1002 TestNetLog log; 1002 TestNetLog log;
1003 scoped_ptr<StreamSocket> transport( 1003 scoped_ptr<StreamSocket> transport(
1004 new TCPClientSocket(addr(), &log, NetLog::Source())); 1004 new TCPClientSocket(addr(), NULL, &log, NetLog::Source()));
1005 int rv = callback.GetResult(transport->Connect(callback.callback())); 1005 int rv = callback.GetResult(transport->Connect(callback.callback()));
1006 EXPECT_EQ(OK, rv); 1006 EXPECT_EQ(OK, rv);
1007 1007
1008 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1008 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1009 std::move(transport), spawned_test_server()->host_port_pair(), 1009 std::move(transport), spawned_test_server()->host_port_pair(),
1010 SSLConfig())); 1010 SSLConfig()));
1011 1011
1012 EXPECT_FALSE(sock->IsConnected()); 1012 EXPECT_FALSE(sock->IsConnected());
1013 1013
1014 rv = sock->Connect(callback.callback()); 1014 rv = sock->Connect(callback.callback());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 // - Server closes the underlying TCP connection directly. 1140 // - Server closes the underlying TCP connection directly.
1141 // - Server sends data unexpectedly. 1141 // - Server sends data unexpectedly.
1142 1142
1143 // Tests that the socket can be read from successfully. Also test that a peer's 1143 // Tests that the socket can be read from successfully. Also test that a peer's
1144 // close_notify alert is successfully processed without error. 1144 // close_notify alert is successfully processed without error.
1145 TEST_F(SSLClientSocketTest, Read) { 1145 TEST_F(SSLClientSocketTest, Read) {
1146 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1146 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1147 1147
1148 TestCompletionCallback callback; 1148 TestCompletionCallback callback;
1149 scoped_ptr<StreamSocket> transport( 1149 scoped_ptr<StreamSocket> transport(
1150 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1150 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1151 EXPECT_EQ(0, transport->GetTotalReceivedBytes()); 1151 EXPECT_EQ(0, transport->GetTotalReceivedBytes());
1152 1152
1153 int rv = callback.GetResult(transport->Connect(callback.callback())); 1153 int rv = callback.GetResult(transport->Connect(callback.callback()));
1154 EXPECT_EQ(OK, rv); 1154 EXPECT_EQ(OK, rv);
1155 1155
1156 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1156 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1157 std::move(transport), spawned_test_server()->host_port_pair(), 1157 std::move(transport), spawned_test_server()->host_port_pair(),
1158 SSLConfig())); 1158 SSLConfig()));
1159 EXPECT_EQ(0, sock->GetTotalReceivedBytes()); 1159 EXPECT_EQ(0, sock->GetTotalReceivedBytes());
1160 1160
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 } 1197 }
1198 1198
1199 // Tests that SSLClientSocket properly handles when the underlying transport 1199 // Tests that SSLClientSocket properly handles when the underlying transport
1200 // synchronously fails a transport read in during the handshake. The error code 1200 // synchronously fails a transport read in during the handshake. The error code
1201 // should be preserved so SSLv3 fallback logic can condition on it. 1201 // should be preserved so SSLv3 fallback logic can condition on it.
1202 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { 1202 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) {
1203 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1203 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1204 1204
1205 TestCompletionCallback callback; 1205 TestCompletionCallback callback;
1206 scoped_ptr<StreamSocket> real_transport( 1206 scoped_ptr<StreamSocket> real_transport(
1207 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1207 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1208 scoped_ptr<SynchronousErrorStreamSocket> transport( 1208 scoped_ptr<SynchronousErrorStreamSocket> transport(
1209 new SynchronousErrorStreamSocket(std::move(real_transport))); 1209 new SynchronousErrorStreamSocket(std::move(real_transport)));
1210 int rv = callback.GetResult(transport->Connect(callback.callback())); 1210 int rv = callback.GetResult(transport->Connect(callback.callback()));
1211 EXPECT_EQ(OK, rv); 1211 EXPECT_EQ(OK, rv);
1212 1212
1213 // Disable TLS False Start to avoid handshake non-determinism. 1213 // Disable TLS False Start to avoid handshake non-determinism.
1214 SSLConfig ssl_config; 1214 SSLConfig ssl_config;
1215 ssl_config.false_start_enabled = false; 1215 ssl_config.false_start_enabled = false;
1216 1216
1217 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1217 SynchronousErrorStreamSocket* raw_transport = transport.get();
(...skipping 10 matching lines...) Expand all
1228 1228
1229 // Tests that the SSLClientSocket properly handles when the underlying transport 1229 // Tests that the SSLClientSocket properly handles when the underlying transport
1230 // synchronously returns an error code - such as if an intermediary terminates 1230 // synchronously returns an error code - such as if an intermediary terminates
1231 // the socket connection uncleanly. 1231 // the socket connection uncleanly.
1232 // This is a regression test for http://crbug.com/238536 1232 // This is a regression test for http://crbug.com/238536
1233 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { 1233 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) {
1234 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1234 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1235 1235
1236 TestCompletionCallback callback; 1236 TestCompletionCallback callback;
1237 scoped_ptr<StreamSocket> real_transport( 1237 scoped_ptr<StreamSocket> real_transport(
1238 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1238 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1239 scoped_ptr<SynchronousErrorStreamSocket> transport( 1239 scoped_ptr<SynchronousErrorStreamSocket> transport(
1240 new SynchronousErrorStreamSocket(std::move(real_transport))); 1240 new SynchronousErrorStreamSocket(std::move(real_transport)));
1241 int rv = callback.GetResult(transport->Connect(callback.callback())); 1241 int rv = callback.GetResult(transport->Connect(callback.callback()));
1242 EXPECT_EQ(OK, rv); 1242 EXPECT_EQ(OK, rv);
1243 1243
1244 // Disable TLS False Start to avoid handshake non-determinism. 1244 // Disable TLS False Start to avoid handshake non-determinism.
1245 SSLConfig ssl_config; 1245 SSLConfig ssl_config;
1246 ssl_config.false_start_enabled = false; 1246 ssl_config.false_start_enabled = false;
1247 1247
1248 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1248 SynchronousErrorStreamSocket* raw_transport = transport.get();
(...skipping 29 matching lines...) Expand all
1278 1278
1279 // Tests that the SSLClientSocket properly handles when the underlying transport 1279 // Tests that the SSLClientSocket properly handles when the underlying transport
1280 // asynchronously returns an error code while writing data - such as if an 1280 // asynchronously returns an error code while writing data - such as if an
1281 // intermediary terminates the socket connection uncleanly. 1281 // intermediary terminates the socket connection uncleanly.
1282 // This is a regression test for http://crbug.com/249848 1282 // This is a regression test for http://crbug.com/249848
1283 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { 1283 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) {
1284 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1284 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1285 1285
1286 TestCompletionCallback callback; 1286 TestCompletionCallback callback;
1287 scoped_ptr<StreamSocket> real_transport( 1287 scoped_ptr<StreamSocket> real_transport(
1288 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1288 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1289 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer 1289 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer
1290 // is retained in order to configure additional errors. 1290 // is retained in order to configure additional errors.
1291 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1291 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1292 new SynchronousErrorStreamSocket(std::move(real_transport))); 1292 new SynchronousErrorStreamSocket(std::move(real_transport)));
1293 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1293 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1294 scoped_ptr<FakeBlockingStreamSocket> transport( 1294 scoped_ptr<FakeBlockingStreamSocket> transport(
1295 new FakeBlockingStreamSocket(std::move(error_socket))); 1295 new FakeBlockingStreamSocket(std::move(error_socket)));
1296 FakeBlockingStreamSocket* raw_transport = transport.get(); 1296 FakeBlockingStreamSocket* raw_transport = transport.get();
1297 int rv = callback.GetResult(transport->Connect(callback.callback())); 1297 int rv = callback.GetResult(transport->Connect(callback.callback()));
1298 EXPECT_EQ(OK, rv); 1298 EXPECT_EQ(OK, rv);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 1345
1346 // If there is a Write failure at the transport with no follow-up Read, although 1346 // If there is a Write failure at the transport with no follow-up Read, although
1347 // the write error will not be returned to the client until a future Read or 1347 // the write error will not be returned to the client until a future Read or
1348 // Write operation, SSLClientSocket should not spin attempting to re-write on 1348 // Write operation, SSLClientSocket should not spin attempting to re-write on
1349 // the socket. This is a regression test for part of https://crbug.com/381160. 1349 // the socket. This is a regression test for part of https://crbug.com/381160.
1350 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) { 1350 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) {
1351 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1351 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1352 1352
1353 TestCompletionCallback callback; 1353 TestCompletionCallback callback;
1354 scoped_ptr<StreamSocket> real_transport( 1354 scoped_ptr<StreamSocket> real_transport(
1355 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1355 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1356 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer 1356 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer
1357 // is retained in order to query them. 1357 // is retained in order to query them.
1358 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1358 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1359 new SynchronousErrorStreamSocket(std::move(real_transport))); 1359 new SynchronousErrorStreamSocket(std::move(real_transport)));
1360 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1360 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1361 scoped_ptr<CountingStreamSocket> counting_socket( 1361 scoped_ptr<CountingStreamSocket> counting_socket(
1362 new CountingStreamSocket(std::move(error_socket))); 1362 new CountingStreamSocket(std::move(error_socket)));
1363 CountingStreamSocket* raw_counting_socket = counting_socket.get(); 1363 CountingStreamSocket* raw_counting_socket = counting_socket.get();
1364 int rv = callback.GetResult(counting_socket->Connect(callback.callback())); 1364 int rv = callback.GetResult(counting_socket->Connect(callback.callback()));
1365 ASSERT_EQ(OK, rv); 1365 ASSERT_EQ(OK, rv);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 // mode when the underlying transport is blocked on sending data. When the 1445 // mode when the underlying transport is blocked on sending data. When the
1446 // underlying transport completes due to an error, it should invoke both the 1446 // underlying transport completes due to an error, it should invoke both the
1447 // Read() and Write() callbacks. If the socket is deleted by the Read() 1447 // Read() and Write() callbacks. If the socket is deleted by the Read()
1448 // callback, the Write() callback should not be invoked. 1448 // callback, the Write() callback should not be invoked.
1449 // Regression test for http://crbug.com/232633 1449 // Regression test for http://crbug.com/232633
1450 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) { 1450 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) {
1451 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1451 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1452 1452
1453 TestCompletionCallback callback; 1453 TestCompletionCallback callback;
1454 scoped_ptr<StreamSocket> real_transport( 1454 scoped_ptr<StreamSocket> real_transport(
1455 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1455 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1456 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer 1456 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer
1457 // is retained in order to configure additional errors. 1457 // is retained in order to configure additional errors.
1458 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1458 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1459 new SynchronousErrorStreamSocket(std::move(real_transport))); 1459 new SynchronousErrorStreamSocket(std::move(real_transport)));
1460 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1460 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1461 scoped_ptr<FakeBlockingStreamSocket> transport( 1461 scoped_ptr<FakeBlockingStreamSocket> transport(
1462 new FakeBlockingStreamSocket(std::move(error_socket))); 1462 new FakeBlockingStreamSocket(std::move(error_socket)));
1463 FakeBlockingStreamSocket* raw_transport = transport.get(); 1463 FakeBlockingStreamSocket* raw_transport = transport.get();
1464 1464
1465 int rv = callback.GetResult(transport->Connect(callback.callback())); 1465 int rv = callback.GetResult(transport->Connect(callback.callback()));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 1554
1555 // Tests that the SSLClientSocket does not crash if data is received on the 1555 // Tests that the SSLClientSocket does not crash if data is received on the
1556 // transport socket after a failing write. This can occur if we have a Write 1556 // transport socket after a failing write. This can occur if we have a Write
1557 // error in a SPDY socket. 1557 // error in a SPDY socket.
1558 // Regression test for http://crbug.com/335557 1558 // Regression test for http://crbug.com/335557
1559 TEST_F(SSLClientSocketTest, Read_WithWriteError) { 1559 TEST_F(SSLClientSocketTest, Read_WithWriteError) {
1560 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1560 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1561 1561
1562 TestCompletionCallback callback; 1562 TestCompletionCallback callback;
1563 scoped_ptr<StreamSocket> real_transport( 1563 scoped_ptr<StreamSocket> real_transport(
1564 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1564 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1565 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer 1565 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer
1566 // is retained in order to configure additional errors. 1566 // is retained in order to configure additional errors.
1567 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1567 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1568 new SynchronousErrorStreamSocket(std::move(real_transport))); 1568 new SynchronousErrorStreamSocket(std::move(real_transport)));
1569 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1569 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1570 scoped_ptr<FakeBlockingStreamSocket> transport( 1570 scoped_ptr<FakeBlockingStreamSocket> transport(
1571 new FakeBlockingStreamSocket(std::move(error_socket))); 1571 new FakeBlockingStreamSocket(std::move(error_socket)));
1572 FakeBlockingStreamSocket* raw_transport = transport.get(); 1572 FakeBlockingStreamSocket* raw_transport = transport.get();
1573 1573
1574 int rv = callback.GetResult(transport->Connect(callback.callback())); 1574 int rv = callback.GetResult(transport->Connect(callback.callback()));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 #endif 1651 #endif
1652 } 1652 }
1653 1653
1654 // Tests that SSLClientSocket fails the handshake if the underlying 1654 // Tests that SSLClientSocket fails the handshake if the underlying
1655 // transport is cleanly closed. 1655 // transport is cleanly closed.
1656 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) { 1656 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) {
1657 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1657 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1658 1658
1659 TestCompletionCallback callback; 1659 TestCompletionCallback callback;
1660 scoped_ptr<StreamSocket> real_transport( 1660 scoped_ptr<StreamSocket> real_transport(
1661 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1661 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1662 scoped_ptr<SynchronousErrorStreamSocket> transport( 1662 scoped_ptr<SynchronousErrorStreamSocket> transport(
1663 new SynchronousErrorStreamSocket(std::move(real_transport))); 1663 new SynchronousErrorStreamSocket(std::move(real_transport)));
1664 int rv = callback.GetResult(transport->Connect(callback.callback())); 1664 int rv = callback.GetResult(transport->Connect(callback.callback()));
1665 EXPECT_EQ(OK, rv); 1665 EXPECT_EQ(OK, rv);
1666 1666
1667 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1667 SynchronousErrorStreamSocket* raw_transport = transport.get();
1668 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1668 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1669 std::move(transport), spawned_test_server()->host_port_pair(), 1669 std::move(transport), spawned_test_server()->host_port_pair(),
1670 SSLConfig())); 1670 SSLConfig()));
1671 1671
1672 raw_transport->SetNextReadError(0); 1672 raw_transport->SetNextReadError(0);
1673 1673
1674 rv = callback.GetResult(sock->Connect(callback.callback())); 1674 rv = callback.GetResult(sock->Connect(callback.callback()));
1675 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); 1675 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv);
1676 EXPECT_FALSE(sock->IsConnected()); 1676 EXPECT_FALSE(sock->IsConnected());
1677 } 1677 }
1678 1678
1679 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket 1679 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket
1680 // is cleanly closed, but the peer does not send close_notify. 1680 // is cleanly closed, but the peer does not send close_notify.
1681 // This is a regression test for https://crbug.com/422246 1681 // This is a regression test for https://crbug.com/422246
1682 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) { 1682 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) {
1683 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1683 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1684 1684
1685 TestCompletionCallback callback; 1685 TestCompletionCallback callback;
1686 scoped_ptr<StreamSocket> real_transport( 1686 scoped_ptr<StreamSocket> real_transport(
1687 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1687 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1688 scoped_ptr<SynchronousErrorStreamSocket> transport( 1688 scoped_ptr<SynchronousErrorStreamSocket> transport(
1689 new SynchronousErrorStreamSocket(std::move(real_transport))); 1689 new SynchronousErrorStreamSocket(std::move(real_transport)));
1690 int rv = callback.GetResult(transport->Connect(callback.callback())); 1690 int rv = callback.GetResult(transport->Connect(callback.callback()));
1691 EXPECT_EQ(OK, rv); 1691 EXPECT_EQ(OK, rv);
1692 1692
1693 // Disable TLS False Start to ensure the handshake has completed. 1693 // Disable TLS False Start to ensure the handshake has completed.
1694 SSLConfig ssl_config; 1694 SSLConfig ssl_config;
1695 ssl_config.false_start_enabled = false; 1695 ssl_config.false_start_enabled = false;
1696 1696
1697 SynchronousErrorStreamSocket* raw_transport = transport.get(); 1697 SynchronousErrorStreamSocket* raw_transport = transport.get();
(...skipping 12 matching lines...) Expand all
1710 } 1710 }
1711 1711
1712 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the 1712 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the
1713 // underlying socket is cleanly closed asynchronously. 1713 // underlying socket is cleanly closed asynchronously.
1714 // This is a regression test for https://crbug.com/422246 1714 // This is a regression test for https://crbug.com/422246
1715 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) { 1715 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) {
1716 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1716 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1717 1717
1718 TestCompletionCallback callback; 1718 TestCompletionCallback callback;
1719 scoped_ptr<StreamSocket> real_transport( 1719 scoped_ptr<StreamSocket> real_transport(
1720 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1720 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1721 scoped_ptr<SynchronousErrorStreamSocket> error_socket( 1721 scoped_ptr<SynchronousErrorStreamSocket> error_socket(
1722 new SynchronousErrorStreamSocket(std::move(real_transport))); 1722 new SynchronousErrorStreamSocket(std::move(real_transport)));
1723 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); 1723 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get();
1724 scoped_ptr<FakeBlockingStreamSocket> transport( 1724 scoped_ptr<FakeBlockingStreamSocket> transport(
1725 new FakeBlockingStreamSocket(std::move(error_socket))); 1725 new FakeBlockingStreamSocket(std::move(error_socket)));
1726 FakeBlockingStreamSocket* raw_transport = transport.get(); 1726 FakeBlockingStreamSocket* raw_transport = transport.get();
1727 int rv = callback.GetResult(transport->Connect(callback.callback())); 1727 int rv = callback.GetResult(transport->Connect(callback.callback()));
1728 EXPECT_EQ(OK, rv); 1728 EXPECT_EQ(OK, rv);
1729 1729
1730 // Disable TLS False Start to ensure the handshake has completed. 1730 // Disable TLS False Start to ensure the handshake has completed.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 EXPECT_GE(rv, 0); 1791 EXPECT_GE(rv, 0);
1792 } while (rv > 0); 1792 } while (rv > 0);
1793 } 1793 }
1794 1794
1795 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) { 1795 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) {
1796 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1796 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1797 1797
1798 TestCompletionCallback callback; 1798 TestCompletionCallback callback;
1799 1799
1800 scoped_ptr<StreamSocket> real_transport( 1800 scoped_ptr<StreamSocket> real_transport(
1801 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1801 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1802 scoped_ptr<ReadBufferingStreamSocket> transport( 1802 scoped_ptr<ReadBufferingStreamSocket> transport(
1803 new ReadBufferingStreamSocket(std::move(real_transport))); 1803 new ReadBufferingStreamSocket(std::move(real_transport)));
1804 ReadBufferingStreamSocket* raw_transport = transport.get(); 1804 ReadBufferingStreamSocket* raw_transport = transport.get();
1805 int rv = callback.GetResult(transport->Connect(callback.callback())); 1805 int rv = callback.GetResult(transport->Connect(callback.callback()));
1806 ASSERT_EQ(OK, rv); 1806 ASSERT_EQ(OK, rv);
1807 1807
1808 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1808 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1809 std::move(transport), spawned_test_server()->host_port_pair(), 1809 std::move(transport), spawned_test_server()->host_port_pair(),
1810 SSLConfig())); 1810 SSLConfig()));
1811 1811
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 EXPECT_GT(rv, 0); 1862 EXPECT_GT(rv, 0);
1863 } 1863 }
1864 1864
1865 TEST_F(SSLClientSocketTest, Read_FullLogging) { 1865 TEST_F(SSLClientSocketTest, Read_FullLogging) {
1866 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1866 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1867 1867
1868 TestCompletionCallback callback; 1868 TestCompletionCallback callback;
1869 TestNetLog log; 1869 TestNetLog log;
1870 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); 1870 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes());
1871 scoped_ptr<StreamSocket> transport( 1871 scoped_ptr<StreamSocket> transport(
1872 new TCPClientSocket(addr(), &log, NetLog::Source())); 1872 new TCPClientSocket(addr(), NULL, &log, NetLog::Source()));
1873 int rv = callback.GetResult(transport->Connect(callback.callback())); 1873 int rv = callback.GetResult(transport->Connect(callback.callback()));
1874 EXPECT_EQ(OK, rv); 1874 EXPECT_EQ(OK, rv);
1875 1875
1876 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 1876 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
1877 std::move(transport), spawned_test_server()->host_port_pair(), 1877 std::move(transport), spawned_test_server()->host_port_pair(),
1878 SSLConfig())); 1878 SSLConfig()));
1879 1879
1880 rv = callback.GetResult(sock->Connect(callback.callback())); 1880 rv = callback.GetResult(sock->Connect(callback.callback()));
1881 EXPECT_EQ(OK, rv); 1881 EXPECT_EQ(OK, rv);
1882 EXPECT_TRUE(sock->IsConnected()); 1882 EXPECT_TRUE(sock->IsConnected());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 1976
1977 // When creating an SSLClientSocket, it is allowed to pass in a 1977 // When creating an SSLClientSocket, it is allowed to pass in a
1978 // ClientSocketHandle that is not obtained from a client socket pool. 1978 // ClientSocketHandle that is not obtained from a client socket pool.
1979 // Here we verify that such a simple ClientSocketHandle, not associated with any 1979 // Here we verify that such a simple ClientSocketHandle, not associated with any
1980 // client socket pool, can be destroyed safely. 1980 // client socket pool, can be destroyed safely.
1981 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { 1981 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) {
1982 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1982 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1983 1983
1984 TestCompletionCallback callback; 1984 TestCompletionCallback callback;
1985 scoped_ptr<StreamSocket> transport( 1985 scoped_ptr<StreamSocket> transport(
1986 new TCPClientSocket(addr(), NULL, NetLog::Source())); 1986 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1987 int rv = callback.GetResult(transport->Connect(callback.callback())); 1987 int rv = callback.GetResult(transport->Connect(callback.callback()));
1988 EXPECT_EQ(OK, rv); 1988 EXPECT_EQ(OK, rv);
1989 1989
1990 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle()); 1990 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle());
1991 socket_handle->SetSocket(std::move(transport)); 1991 socket_handle->SetSocket(std::move(transport));
1992 1992
1993 scoped_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket( 1993 scoped_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket(
1994 std::move(socket_handle), spawned_test_server()->host_port_pair(), 1994 std::move(socket_handle), spawned_test_server()->host_port_pair(),
1995 SSLConfig(), context_)); 1995 SSLConfig(), context_));
1996 1996
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 } 2505 }
2506 2506
2507 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't 2507 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't
2508 // been flushed completely out of SSLClientSocket's internal buffers. This is a 2508 // been flushed completely out of SSLClientSocket's internal buffers. This is a
2509 // regression test for https://crbug.com/466147. 2509 // regression test for https://crbug.com/466147.
2510 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { 2510 TEST_F(SSLClientSocketTest, ReusableAfterWrite) {
2511 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 2511 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
2512 2512
2513 TestCompletionCallback callback; 2513 TestCompletionCallback callback;
2514 scoped_ptr<StreamSocket> real_transport( 2514 scoped_ptr<StreamSocket> real_transport(
2515 new TCPClientSocket(addr(), NULL, NetLog::Source())); 2515 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
2516 scoped_ptr<FakeBlockingStreamSocket> transport( 2516 scoped_ptr<FakeBlockingStreamSocket> transport(
2517 new FakeBlockingStreamSocket(std::move(real_transport))); 2517 new FakeBlockingStreamSocket(std::move(real_transport)));
2518 FakeBlockingStreamSocket* raw_transport = transport.get(); 2518 FakeBlockingStreamSocket* raw_transport = transport.get();
2519 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); 2519 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback())));
2520 2520
2521 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( 2521 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket(
2522 std::move(transport), spawned_test_server()->host_port_pair(), 2522 std::move(transport), spawned_test_server()->host_port_pair(),
2523 SSLConfig())); 2523 SSLConfig()));
2524 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); 2524 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback())));
2525 2525
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2561 2561
2562 // The next connection should resume. 2562 // The next connection should resume.
2563 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 2563 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2564 ASSERT_EQ(OK, rv); 2564 ASSERT_EQ(OK, rv);
2565 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 2565 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
2566 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); 2566 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type);
2567 sock_.reset(); 2567 sock_.reset();
2568 2568
2569 // Using a different HostPortPair uses a different session cache key. 2569 // Using a different HostPortPair uses a different session cache key.
2570 scoped_ptr<StreamSocket> transport( 2570 scoped_ptr<StreamSocket> transport(
2571 new TCPClientSocket(addr(), &log_, NetLog::Source())); 2571 new TCPClientSocket(addr(), NULL, &log_, NetLog::Source()));
2572 TestCompletionCallback callback; 2572 TestCompletionCallback callback;
2573 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); 2573 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback())));
2574 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( 2574 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket(
2575 std::move(transport), HostPortPair("example.com", 443), ssl_config); 2575 std::move(transport), HostPortPair("example.com", 443), ssl_config);
2576 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); 2576 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback())));
2577 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); 2577 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info));
2578 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); 2578 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2579 sock.reset(); 2579 sock.reset();
2580 2580
2581 SSLClientSocket::ClearSessionCache(); 2581 SSLClientSocket::ClearSessionCache();
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 SSLInfo ssl_info; 3365 SSLInfo ssl_info;
3366 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 3366 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
3367 EXPECT_TRUE(ssl_info.client_cert_sent); 3367 EXPECT_TRUE(ssl_info.client_cert_sent);
3368 3368
3369 sock_->Disconnect(); 3369 sock_->Disconnect();
3370 EXPECT_FALSE(sock_->IsConnected()); 3370 EXPECT_FALSE(sock_->IsConnected());
3371 } 3371 }
3372 #endif // defined(USE_OPENSSL) 3372 #endif // defined(USE_OPENSSL)
3373 3373
3374 } // namespace net 3374 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698