Chromium Code Reviews| 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 // 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 class FakeDataChannel { | 55 class FakeDataChannel { |
| 56 public: | 56 public: |
| 57 FakeDataChannel() | 57 FakeDataChannel() |
| 58 : read_buf_len_(0), | 58 : read_buf_len_(0), |
| 59 closed_(false), | 59 closed_(false), |
| 60 write_called_after_close_(false), | 60 write_called_after_close_(false), |
| 61 weak_factory_(this) { | 61 weak_factory_(this) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback) { | 64 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback) { |
| 65 DCHECK(read_callback_.is_null()); | |
| 66 DCHECK(!read_buf_); | |
| 65 if (closed_) | 67 if (closed_) |
| 66 return 0; | 68 return 0; |
| 67 if (data_.empty()) { | 69 if (data_.empty()) { |
| 68 read_callback_ = callback; | 70 read_callback_ = callback; |
| 69 read_buf_ = buf; | 71 read_buf_ = buf; |
| 70 read_buf_len_ = buf_len; | 72 read_buf_len_ = buf_len; |
| 71 return net::ERR_IO_PENDING; | 73 return net::ERR_IO_PENDING; |
|
Ryan Sleevi
2014/07/15 20:09:53
I'll send you a cookie* if you want to grab a foll
| |
| 72 } | 74 } |
| 73 return PropogateData(buf, buf_len); | 75 return PropogateData(buf, buf_len); |
| 74 } | 76 } |
| 75 | 77 |
| 76 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback) { | 78 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback) { |
| 79 DCHECK(write_callback_.is_null()); | |
| 77 if (closed_) { | 80 if (closed_) { |
| 78 if (write_called_after_close_) | 81 if (write_called_after_close_) |
| 79 return net::ERR_CONNECTION_RESET; | 82 return net::ERR_CONNECTION_RESET; |
| 80 write_called_after_close_ = true; | 83 write_called_after_close_ = true; |
| 81 write_callback_ = callback; | 84 write_callback_ = callback; |
| 82 base::MessageLoop::current()->PostTask( | 85 base::MessageLoop::current()->PostTask( |
| 83 FROM_HERE, base::Bind(&FakeDataChannel::DoWriteCallback, | 86 FROM_HERE, base::Bind(&FakeDataChannel::DoWriteCallback, |
| 84 weak_factory_.GetWeakPtr())); | 87 weak_factory_.GetWeakPtr())); |
| 85 return net::ERR_IO_PENDING; | 88 return net::ERR_IO_PENDING; |
| 86 } | 89 } |
| 87 data_.push(new net::DrainableIOBuffer(buf, buf_len)); | 90 // This function returns synchronously, so make a copy of the buffer. |
| 91 data_.push(new net::DrainableIOBuffer( | |
| 92 new net::StringIOBuffer(std::string(buf->data(), buf_len)), | |
| 93 buf_len)); | |
| 88 base::MessageLoop::current()->PostTask( | 94 base::MessageLoop::current()->PostTask( |
| 89 FROM_HERE, base::Bind(&FakeDataChannel::DoReadCallback, | 95 FROM_HERE, base::Bind(&FakeDataChannel::DoReadCallback, |
| 90 weak_factory_.GetWeakPtr())); | 96 weak_factory_.GetWeakPtr())); |
| 91 return buf_len; | 97 return buf_len; |
| 92 } | 98 } |
| 93 | 99 |
| 94 // Closes the FakeDataChannel. After Close() is called, Read() returns 0, | 100 // Closes the FakeDataChannel. After Close() is called, Read() returns 0, |
| 95 // indicating EOF, and Write() fails with ERR_CONNECTION_RESET. Note that | 101 // indicating EOF, and Write() fails with ERR_CONNECTION_RESET. Note that |
| 96 // after the FakeDataChannel is closed, the first Write() call completes | 102 // after the FakeDataChannel is closed, the first Write() call completes |
| 97 // asynchronously, which is necessary to reproduce bug 127822. | 103 // asynchronously, which is necessary to reproduce bug 127822. |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | 476 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); |
| 471 server_ret = read_callback.GetResult(server_ret); | 477 server_ret = read_callback.GetResult(server_ret); |
| 472 ASSERT_GT(server_ret, 0); | 478 ASSERT_GT(server_ret, 0); |
| 473 read_buf->DidConsume(server_ret); | 479 read_buf->DidConsume(server_ret); |
| 474 } | 480 } |
| 475 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed()); | 481 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed()); |
| 476 read_buf->SetOffset(0); | 482 read_buf->SetOffset(0); |
| 477 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); | 483 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); |
| 478 } | 484 } |
| 479 | 485 |
| 480 // Flaky on Android: http://crbug.com/381147 | |
| 481 #if defined(OS_ANDROID) | |
| 482 #define MAYBE_ClientWriteAfterServerClose DISABLED_ClientWriteAfterServerClose | |
| 483 #else | |
| 484 #define MAYBE_ClientWriteAfterServerClose ClientWriteAfterServerClose | |
| 485 #endif | |
| 486 // A regression test for bug 127822 (http://crbug.com/127822). | 486 // A regression test for bug 127822 (http://crbug.com/127822). |
| 487 // If the server closes the connection after the handshake is finished, | 487 // If the server closes the connection after the handshake is finished, |
| 488 // the client's Write() call should not cause an infinite loop. | 488 // the client's Write() call should not cause an infinite loop. |
| 489 // NOTE: this is a test for SSLClientSocket rather than SSLServerSocket. | 489 // NOTE: this is a test for SSLClientSocket rather than SSLServerSocket. |
| 490 TEST_F(SSLServerSocketTest, MAYBE_ClientWriteAfterServerClose) { | 490 TEST_F(SSLServerSocketTest, ClientWriteAfterServerClose) { |
| 491 Initialize(); | 491 Initialize(); |
| 492 | 492 |
| 493 TestCompletionCallback connect_callback; | 493 TestCompletionCallback connect_callback; |
| 494 TestCompletionCallback handshake_callback; | 494 TestCompletionCallback handshake_callback; |
| 495 | 495 |
| 496 // Establish connection. | 496 // Establish connection. |
| 497 int client_ret = client_socket_->Connect(connect_callback.callback()); | 497 int client_ret = client_socket_->Connect(connect_callback.callback()); |
| 498 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); | 498 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); |
| 499 | 499 |
| 500 int server_ret = server_socket_->Handshake(handshake_callback.callback()); | 500 int server_ret = server_socket_->Handshake(handshake_callback.callback()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; | 578 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; |
| 579 unsigned char client_bad[kKeyingMaterialSize]; | 579 unsigned char client_bad[kKeyingMaterialSize]; |
| 580 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, | 580 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, |
| 581 false, kKeyingContext, | 581 false, kKeyingContext, |
| 582 client_bad, sizeof(client_bad)); | 582 client_bad, sizeof(client_bad)); |
| 583 ASSERT_EQ(rv, net::OK); | 583 ASSERT_EQ(rv, net::OK); |
| 584 EXPECT_NE(0, memcmp(server_out, client_bad, sizeof(server_out))); | 584 EXPECT_NE(0, memcmp(server_out, client_bad, sizeof(server_out))); |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace net | 587 } // namespace net |
| OLD | NEW |