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

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

Powered by Google App Engine
This is Rietveld 408576698