| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This test suite uses SSLClientSocket to test the implementation of | 5 // This test suite uses SSLClientSocket to test the implementation of |
| 6 // SSLServerSocket. In order to establish connections between the sockets | 6 // SSLServerSocket. In order to establish connections between the sockets |
| 7 // we need two additional classes: | 7 // we need two additional classes: |
| 8 // 1. FakeSocket | 8 // 1. FakeSocket |
| 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. | 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. |
| 10 // | 10 // |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // SSLServerSocket is only implemented using NSS. | 277 // SSLServerSocket is only implemented using NSS. |
| 278 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) | 278 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
| 279 | 279 |
| 280 // This test only executes creation of client and server sockets. This is to | 280 // This test only executes creation of client and server sockets. This is to |
| 281 // test that creation of sockets doesn't crash and have minimal code to run | 281 // test that creation of sockets doesn't crash and have minimal code to run |
| 282 // under valgrind in order to help debugging memory problems. | 282 // under valgrind in order to help debugging memory problems. |
| 283 TEST_F(SSLServerSocketTest, Initialize) { | 283 TEST_F(SSLServerSocketTest, Initialize) { |
| 284 Initialize(); | 284 Initialize(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 // This test executes Connect() of SSLClientSocket and Accept() of | 287 // This test executes Connect() on SSLClientSocket and Handshake() on |
| 288 // SSLServerSocket to make sure handshaking between the two sockets are | 288 // SSLServerSocket to make sure handshaking between the two sockets is |
| 289 // completed successfully. | 289 // completed successfully. |
| 290 TEST_F(SSLServerSocketTest, Handshake) { | 290 TEST_F(SSLServerSocketTest, Handshake) { |
| 291 Initialize(); | 291 Initialize(); |
| 292 | 292 |
| 293 TestCompletionCallback connect_callback; | 293 TestCompletionCallback connect_callback; |
| 294 TestCompletionCallback accept_callback; | 294 TestCompletionCallback accept_callback; |
| 295 | 295 |
| 296 int server_ret = server_socket_->Accept(&accept_callback); | 296 int server_ret = server_socket_->Handshake(&accept_callback); |
| 297 EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); | 297 EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); |
| 298 | 298 |
| 299 int client_ret = client_socket_->Connect(&connect_callback); | 299 int client_ret = client_socket_->Connect(&connect_callback); |
| 300 EXPECT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); | 300 EXPECT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); |
| 301 | 301 |
| 302 if (client_ret == net::ERR_IO_PENDING) { | 302 if (client_ret == net::ERR_IO_PENDING) { |
| 303 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); | 303 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); |
| 304 } | 304 } |
| 305 if (server_ret == net::ERR_IO_PENDING) { | 305 if (server_ret == net::ERR_IO_PENDING) { |
| 306 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); | 306 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); |
| 307 } | 307 } |
| 308 | 308 |
| 309 // Make sure the cert status is expected. | 309 // Make sure the cert status is expected. |
| 310 SSLInfo ssl_info; | 310 SSLInfo ssl_info; |
| 311 client_socket_->GetSSLInfo(&ssl_info); | 311 client_socket_->GetSSLInfo(&ssl_info); |
| 312 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, ssl_info.cert_status); | 312 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, ssl_info.cert_status); |
| 313 } | 313 } |
| 314 | 314 |
| 315 TEST_F(SSLServerSocketTest, DataTransfer) { | 315 TEST_F(SSLServerSocketTest, DataTransfer) { |
| 316 Initialize(); | 316 Initialize(); |
| 317 | 317 |
| 318 TestCompletionCallback connect_callback; | 318 TestCompletionCallback connect_callback; |
| 319 TestCompletionCallback accept_callback; | 319 TestCompletionCallback accept_callback; |
| 320 | 320 |
| 321 // Establish connection. | 321 // Establish connection. |
| 322 int client_ret = client_socket_->Connect(&connect_callback); | 322 int client_ret = client_socket_->Connect(&connect_callback); |
| 323 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); | 323 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); |
| 324 | 324 |
| 325 int server_ret = server_socket_->Accept(&accept_callback); | 325 int server_ret = server_socket_->Handshake(&accept_callback); |
| 326 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); | 326 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); |
| 327 | 327 |
| 328 if (client_ret == net::ERR_IO_PENDING) { | 328 if (client_ret == net::ERR_IO_PENDING) { |
| 329 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); | 329 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); |
| 330 } | 330 } |
| 331 if (server_ret == net::ERR_IO_PENDING) { | 331 if (server_ret == net::ERR_IO_PENDING) { |
| 332 ASSERT_EQ(net::OK, accept_callback.WaitForResult()); | 332 ASSERT_EQ(net::OK, accept_callback.WaitForResult()); |
| 333 } | 333 } |
| 334 | 334 |
| 335 const int kReadBufSize = 1024; | 335 const int kReadBufSize = 1024; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 366 EXPECT_GT(read_callback.WaitForResult(), 0); | 366 EXPECT_GT(read_callback.WaitForResult(), 0); |
| 367 } | 367 } |
| 368 if (client_ret == net::ERR_IO_PENDING) { | 368 if (client_ret == net::ERR_IO_PENDING) { |
| 369 EXPECT_GT(write_callback.WaitForResult(), 0); | 369 EXPECT_GT(write_callback.WaitForResult(), 0); |
| 370 } | 370 } |
| 371 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); | 371 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); |
| 372 } | 372 } |
| 373 #endif | 373 #endif |
| 374 | 374 |
| 375 } // namespace net | 375 } // namespace net |
| OLD | NEW |