| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "blimp/net/blimp_connection.h" | 8 #include "blimp/net/blimp_connection.h" |
| 9 #include "blimp/net/blimp_connection_statistics.h" | |
| 10 #include "blimp/net/ssl_client_transport.h" | 9 #include "blimp/net/ssl_client_transport.h" |
| 11 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| 12 #include "net/base/ip_address.h" | 11 #include "net/base/ip_address.h" |
| 13 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 14 #include "net/socket/socket_test_util.h" | 13 #include "net/socket/socket_test_util.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 namespace blimp { | 17 namespace blimp { |
| 19 namespace { | 18 namespace { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 53 } |
| 55 | 54 |
| 56 void SetupSSLAsyncSocketConnect(int result) { | 55 void SetupSSLAsyncSocketConnect(int result) { |
| 57 ssl_connect_.reset(new net::SSLSocketDataProvider(net::ASYNC, result)); | 56 ssl_connect_.reset(new net::SSLSocketDataProvider(net::ASYNC, result)); |
| 58 socket_factory_.AddSSLSocketDataProvider(ssl_connect_.get()); | 57 socket_factory_.AddSSLSocketDataProvider(ssl_connect_.get()); |
| 59 } | 58 } |
| 60 | 59 |
| 61 void ConfigureTransport(const net::IPEndPoint& ip_endpoint) { | 60 void ConfigureTransport(const net::IPEndPoint& ip_endpoint) { |
| 62 // The mock does not interact with the cert directly, so just leave it null. | 61 // The mock does not interact with the cert directly, so just leave it null. |
| 63 scoped_refptr<net::X509Certificate> cert; | 62 scoped_refptr<net::X509Certificate> cert; |
| 64 transport_.reset( | 63 transport_.reset(new SSLClientTransport(ip_endpoint, cert, &net_log_)); |
| 65 new SSLClientTransport(ip_endpoint, cert, &statistics_, &net_log_)); | |
| 66 transport_->SetClientSocketFactoryForTest(&socket_factory_); | 64 transport_->SetClientSocketFactoryForTest(&socket_factory_); |
| 67 } | 65 } |
| 68 | 66 |
| 69 base::MessageLoop message_loop; | 67 base::MessageLoop message_loop; |
| 70 BlimpConnectionStatistics statistics_; | |
| 71 net::NetLog net_log_; | 68 net::NetLog net_log_; |
| 72 net::StaticSocketDataProvider tcp_connect_; | 69 net::StaticSocketDataProvider tcp_connect_; |
| 73 std::unique_ptr<net::SSLSocketDataProvider> ssl_connect_; | 70 std::unique_ptr<net::SSLSocketDataProvider> ssl_connect_; |
| 74 net::MockClientSocketFactory socket_factory_; | 71 net::MockClientSocketFactory socket_factory_; |
| 75 std::unique_ptr<SSLClientTransport> transport_; | 72 std::unique_ptr<SSLClientTransport> transport_; |
| 76 }; | 73 }; |
| 77 | 74 |
| 78 TEST_F(SSLClientTransportTest, ConnectSyncOK) { | 75 TEST_F(SSLClientTransportTest, ConnectSyncOK) { |
| 79 net::IPEndPoint endpoint(kIPV4Address, kPort); | 76 net::IPEndPoint endpoint(kIPV4Address, kPort); |
| 80 ConfigureTransport(endpoint); | 77 ConfigureTransport(endpoint); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 EXPECT_CALL(*this, ConnectComplete(net::OK)); | 153 EXPECT_CALL(*this, ConnectComplete(net::OK)); |
| 157 SetupTCPSyncSocketConnect(endpoint, net::OK); | 154 SetupTCPSyncSocketConnect(endpoint, net::OK); |
| 158 SetupSSLSyncSocketConnect(net::OK); | 155 SetupSSLSyncSocketConnect(net::OK); |
| 159 transport_->Connect(base::Bind(&SSLClientTransportTest::ConnectComplete, | 156 transport_->Connect(base::Bind(&SSLClientTransportTest::ConnectComplete, |
| 160 base::Unretained(this))); | 157 base::Unretained(this))); |
| 161 EXPECT_NE(nullptr, transport_->TakeConnection().get()); | 158 EXPECT_NE(nullptr, transport_->TakeConnection().get()); |
| 162 base::RunLoop().RunUntilIdle(); | 159 base::RunLoop().RunUntilIdle(); |
| 163 } | 160 } |
| 164 | 161 |
| 165 } // namespace blimp | 162 } // namespace blimp |
| OLD | NEW |