OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 2713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2724 if (sock->IsConnected()) | 2724 if (sock->IsConnected()) |
2725 LOG(ERROR) << "SSL Socket prematurely connected"; | 2725 LOG(ERROR) << "SSL Socket prematurely connected"; |
2726 | 2726 |
2727 rv = callback.GetResult(sock->Connect(callback.callback())); | 2727 rv = callback.GetResult(sock->Connect(callback.callback())); |
2728 | 2728 |
2729 EXPECT_EQ(OK, rv); | 2729 EXPECT_EQ(OK, rv); |
2730 EXPECT_TRUE(sock->IsConnected()); | 2730 EXPECT_TRUE(sock->IsConnected()); |
2731 EXPECT_TRUE(ran_handshake_completion_callback_); | 2731 EXPECT_TRUE(ran_handshake_completion_callback_); |
2732 } | 2732 } |
2733 | 2733 |
| 2734 // Tests that the completion callback is run with connections |
| 2735 // that do not cache their session. |
| 2736 TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithNoneSessionCache) { |
| 2737 SpawnedTestServer::SSLOptions ssl_options; |
| 2738 ssl_options.none_session_cache = true; |
| 2739 SpawnedTestServer test_server( |
| 2740 SpawnedTestServer::TYPE_HTTPS, ssl_options, base::FilePath()); |
| 2741 ASSERT_TRUE(test_server.Start()); |
| 2742 |
| 2743 AddressList addr; |
| 2744 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 2745 |
| 2746 scoped_ptr<StreamSocket> transport( |
| 2747 new TCPClientSocket(addr, NULL, NetLog::Source())); |
| 2748 |
| 2749 TestCompletionCallback callback; |
| 2750 int rv = transport->Connect(callback.callback()); |
| 2751 if (rv == ERR_IO_PENDING) |
| 2752 rv = callback.WaitForResult(); |
| 2753 EXPECT_EQ(OK, rv); |
| 2754 |
| 2755 SSLConfig ssl_config = kDefaultSSLConfig; |
| 2756 ssl_config.false_start_enabled = false; |
| 2757 |
| 2758 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 2759 transport.Pass(), test_server.host_port_pair(), ssl_config)); |
| 2760 |
| 2761 sock->SetHandshakeCompletionCallback(base::Bind( |
| 2762 &SSLClientSocketTest::RecordCompletedHandshake, base::Unretained(this))); |
| 2763 |
| 2764 if (sock->IsConnected()) |
| 2765 LOG(ERROR) << "SSL Socket prematurely connected"; |
| 2766 |
| 2767 rv = callback.GetResult(sock->Connect(callback.callback())); |
| 2768 |
| 2769 EXPECT_EQ(OK, rv); |
| 2770 EXPECT_TRUE(sock->IsConnected()); |
| 2771 EXPECT_TRUE(ran_handshake_completion_callback_); |
| 2772 } |
2734 #endif // defined(USE_OPENSSL) | 2773 #endif // defined(USE_OPENSSL) |
2735 | 2774 |
2736 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { | 2775 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { |
2737 // False Start requires NPN and a forward-secret cipher suite. | 2776 // False Start requires NPN and a forward-secret cipher suite. |
2738 SpawnedTestServer::SSLOptions server_options; | 2777 SpawnedTestServer::SSLOptions server_options; |
2739 server_options.key_exchanges = | 2778 server_options.key_exchanges = |
2740 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2779 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
2741 server_options.enable_npn = true; | 2780 server_options.enable_npn = true; |
2742 SSLConfig client_config; | 2781 SSLConfig client_config; |
2743 client_config.next_protos.push_back("http/1.1"); | 2782 client_config.next_protos.push_back("http/1.1"); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2895 ssl_config.channel_id_enabled = true; | 2934 ssl_config.channel_id_enabled = true; |
2896 | 2935 |
2897 int rv; | 2936 int rv; |
2898 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2937 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
2899 | 2938 |
2900 EXPECT_EQ(ERR_UNEXPECTED, rv); | 2939 EXPECT_EQ(ERR_UNEXPECTED, rv); |
2901 EXPECT_FALSE(sock_->IsConnected()); | 2940 EXPECT_FALSE(sock_->IsConnected()); |
2902 } | 2941 } |
2903 | 2942 |
2904 } // namespace net | 2943 } // namespace net |
OLD | NEW |