Chromium Code Reviews| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 if (client_ret == net::ERR_IO_PENDING) { | 364 if (client_ret == net::ERR_IO_PENDING) { |
| 365 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); | 365 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); |
| 366 } | 366 } |
| 367 if (server_ret == net::ERR_IO_PENDING) { | 367 if (server_ret == net::ERR_IO_PENDING) { |
| 368 ASSERT_EQ(net::OK, handshake_callback.WaitForResult()); | 368 ASSERT_EQ(net::OK, handshake_callback.WaitForResult()); |
| 369 } | 369 } |
| 370 | 370 |
| 371 const int kReadBufSize = 1024; | 371 const int kReadBufSize = 1024; |
| 372 scoped_refptr<net::StringIOBuffer> write_buf = | 372 scoped_refptr<net::StringIOBuffer> write_buf = |
| 373 new net::StringIOBuffer("testing123"); | 373 new net::StringIOBuffer("testing123"); |
| 374 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(kReadBufSize); | 374 scoped_refptr<net::DrainableIOBuffer> read_buf = |
| 375 new net::DrainableIOBuffer(new net::IOBuffer(kReadBufSize), | |
| 376 kReadBufSize); | |
| 375 | 377 |
| 376 // Write then read. | 378 // Write then read. |
| 377 TestCompletionCallback write_callback; | 379 TestCompletionCallback write_callback; |
| 378 TestCompletionCallback read_callback; | 380 TestCompletionCallback read_callback; |
| 379 server_ret = server_socket_->Write(write_buf, write_buf->size(), | 381 server_ret = server_socket_->Write(write_buf, write_buf->size(), |
| 380 &write_callback); | 382 &write_callback); |
| 381 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | 383 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); |
| 382 client_ret = client_socket_->Read(read_buf, kReadBufSize, &read_callback); | 384 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(), |
|
rvargas (doing something else)
2011/08/15 18:31:41
Is it important for this test that the write and t
wtc
2011/08/16 00:04:05
I am not sure either. I can implement this change
| |
| 385 &read_callback); | |
| 383 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); | 386 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); |
| 384 | 387 |
| 385 if (server_ret == net::ERR_IO_PENDING) { | 388 if (server_ret == net::ERR_IO_PENDING) { |
|
rvargas (doing something else)
2011/08/15 18:31:41
This can be simplified with write_callback.GetResu
| |
| 386 EXPECT_GT(write_callback.WaitForResult(), 0); | 389 server_ret = write_callback.WaitForResult(); |
| 390 EXPECT_GT(server_ret, 0); | |
| 387 } | 391 } |
| 388 if (client_ret == net::ERR_IO_PENDING) { | 392 if (client_ret == net::ERR_IO_PENDING) { |
| 389 EXPECT_GT(read_callback.WaitForResult(), 0); | 393 client_ret = read_callback.WaitForResult(); |
| 394 EXPECT_GT(client_ret, 0); | |
| 390 } | 395 } |
| 396 int bytes_read = client_ret; | |
| 397 read_buf->DidConsume(client_ret); | |
| 398 while (bytes_read < write_buf->size()) { | |
| 399 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(), | |
| 400 &read_callback); | |
| 401 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); | |
| 402 if (client_ret == net::ERR_IO_PENDING) { | |
| 403 client_ret = read_callback.WaitForResult(); | |
| 404 EXPECT_GT(client_ret, 0); | |
|
rvargas (doing something else)
2011/08/15 18:31:41
If we really care about failures, we should add co
| |
| 405 } | |
| 406 bytes_read += client_ret; | |
|
rvargas (doing something else)
2011/08/15 18:31:41
nit: we could use BytesConsumed() here, instead of
| |
| 407 read_buf->DidConsume(client_ret); | |
| 408 } | |
| 409 read_buf->SetOffset(0); | |
| 410 EXPECT_EQ(write_buf->size(), bytes_read); | |
| 391 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); | 411 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); |
| 392 | 412 |
| 393 // Read then write. | 413 // Read then write. |
|
rvargas (doing something else)
2011/08/15 18:31:41
Looks like we are not really doing this.
| |
| 394 write_buf = new net::StringIOBuffer("hello123"); | 414 write_buf = new net::StringIOBuffer("hello123"); |
| 395 server_ret = server_socket_->Read(read_buf, kReadBufSize, &read_callback); | 415 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(), |
| 416 &read_callback); | |
| 396 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | 417 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); |
| 397 client_ret = client_socket_->Write(write_buf, write_buf->size(), | 418 client_ret = client_socket_->Write(write_buf, write_buf->size(), |
| 398 &write_callback); | 419 &write_callback); |
| 399 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); | 420 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); |
| 400 | 421 |
| 401 if (server_ret == net::ERR_IO_PENDING) { | 422 if (server_ret == net::ERR_IO_PENDING) { |
| 402 EXPECT_GT(read_callback.WaitForResult(), 0); | 423 server_ret = read_callback.WaitForResult(); |
| 424 EXPECT_GT(server_ret, 0); | |
| 403 } | 425 } |
| 404 if (client_ret == net::ERR_IO_PENDING) { | 426 if (client_ret == net::ERR_IO_PENDING) { |
| 405 EXPECT_GT(write_callback.WaitForResult(), 0); | 427 client_ret = write_callback.WaitForResult(); |
| 428 EXPECT_GT(client_ret, 0); | |
| 406 } | 429 } |
| 430 bytes_read = server_ret; | |
| 431 read_buf->DidConsume(server_ret); | |
| 432 while (bytes_read < write_buf->size()) { | |
| 433 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(), | |
| 434 &read_callback); | |
| 435 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | |
| 436 if (server_ret == net::ERR_IO_PENDING) { | |
| 437 server_ret = read_callback.WaitForResult(); | |
| 438 EXPECT_GT(server_ret, 0); | |
| 439 } | |
| 440 bytes_read += server_ret; | |
| 441 read_buf->DidConsume(server_ret); | |
| 442 } | |
| 443 read_buf->SetOffset(0); | |
| 444 EXPECT_EQ(write_buf->size(), bytes_read); | |
| 407 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); | 445 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); |
| 408 } | 446 } |
| 409 | 447 |
| 410 // This test executes ExportKeyingMaterial() on the client and server sockets, | 448 // This test executes ExportKeyingMaterial() on the client and server sockets, |
| 411 // after connecting them, and verifies that the results match. | 449 // after connecting them, and verifies that the results match. |
| 412 // This test will fail if False Start is enabled (see crbug.com/90208). | 450 // This test will fail if False Start is enabled (see crbug.com/90208). |
| 413 TEST_F(SSLServerSocketTest, ExportKeyingMaterial) { | 451 TEST_F(SSLServerSocketTest, ExportKeyingMaterial) { |
| 414 Initialize(); | 452 Initialize(); |
| 415 | 453 |
| 416 TestCompletionCallback connect_callback; | 454 TestCompletionCallback connect_callback; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 446 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; | 484 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; |
| 447 unsigned char client_bad[kKeyingMaterialSize]; | 485 unsigned char client_bad[kKeyingMaterialSize]; |
| 448 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, | 486 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, |
| 449 client_bad, sizeof(client_bad)); | 487 client_bad, sizeof(client_bad)); |
| 450 ASSERT_EQ(rv, net::OK); | 488 ASSERT_EQ(rv, net::OK); |
| 451 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); | 489 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); |
| 452 } | 490 } |
| 453 #endif | 491 #endif |
| 454 | 492 |
| 455 } // namespace net | 493 } // namespace net |
| OLD | NEW |