Index: webrtc/base/ssladapter_unittest.cc |
diff --git a/webrtc/base/ssladapter_unittest.cc b/webrtc/base/ssladapter_unittest.cc |
index ec39d949a2c764680ffc05990d3f06d2b3191a07..0eaac17885ac40d2e54c89cf8618b9dd2d473263 100644 |
--- a/webrtc/base/ssladapter_unittest.cc |
+++ b/webrtc/base/ssladapter_unittest.cc |
@@ -15,9 +15,10 @@ |
#include "webrtc/base/ipaddress.h" |
#include "webrtc/base/socketstream.h" |
#include "webrtc/base/ssladapter.h" |
-#include "webrtc/base/sslstreamadapter.h" |
#include "webrtc/base/sslidentity.h" |
+#include "webrtc/base/sslstreamadapter.h" |
#include "webrtc/base/stream.h" |
+#include "webrtc/base/stringencode.h" |
#include "webrtc/base/virtualsocketserver.h" |
static const int kTimeout = 5000; |
@@ -210,19 +211,16 @@ class SSLAdapterTestDummyServer : public sigslot::has_slots<> { |
void OnSSLStreamAdapterEvent(rtc::StreamInterface* stream, int sig, int err) { |
if (sig & rtc::SE_READ) { |
char buffer[4096] = ""; |
- |
size_t read; |
int error; |
// Read data received from the client and store it in our internal |
// buffer. |
- rtc::StreamResult r = stream->Read(buffer, |
- sizeof(buffer) - 1, &read, &error); |
+ rtc::StreamResult r = |
+ stream->Read(buffer, sizeof(buffer) - 1, &read, &error); |
if (r == rtc::SR_SUCCESS) { |
buffer[read] = '\0'; |
- |
LOG(LS_INFO) << "Server received '" << buffer << "'"; |
- |
data_ += buffer; |
} |
} |
@@ -336,7 +334,7 @@ class SSLAdapterTestBase : public testing::Test, |
LOG(LS_INFO) << "Transfer complete."; |
} |
- private: |
+ protected: |
const rtc::SSLMode ssl_mode_; |
std::unique_ptr<rtc::VirtualSocketServer> vss_; |
@@ -389,6 +387,47 @@ TEST_F(SSLAdapterTestTLS_RSA, TestTLSTransfer) { |
TestTransfer("Hello, world!"); |
} |
+TEST_F(SSLAdapterTestTLS_RSA, TestTLSTransferWithBlockedSocket) { |
+ TestHandshake(true); |
+ |
+ // Tell the underlying socket to simulate being blocked. |
+ vss_->SetSendingBlocked(true); |
+ |
+ std::string expected; |
+ int rv; |
+ // Send messages until the SSL socket adapter starts applying backpressure. |
+ // Note that this may not occur immediately since there may be some amount of |
+ // intermediate buffering (either in our code or in BoringSSL). |
+ for (int i = 0; i < 1024; ++i) { |
+ std::string message = "Hello, world: " + rtc::ToString(i); |
+ rv = client_->Send(message); |
+ if (rv != static_cast<int>(message.size())) { |
+ // This test assumes either the whole message or none of it is sent. |
+ ASSERT_EQ(-1, rv); |
+ break; |
+ } |
+ expected += message; |
+ } |
+ // Assert that the loop above exited due to Send returning -1. |
+ ASSERT_EQ(-1, rv); |
+ |
+ // Try sending another message while blocked. -1 should be returned again and |
+ // it shouldn't end up received by the server later. |
+ EXPECT_EQ(-1, client_->Send("Never sent")); |
+ |
+ // Unblock the underlying socket. All of the buffered messages should be sent |
+ // without any further action. |
+ vss_->SetSendingBlocked(false); |
+ EXPECT_EQ_WAIT(expected, server_->GetReceivedData(), kTimeout); |
+ |
+ // Send another message. This previously wasn't working |
+ std::string final_message = "Fin."; |
+ expected += final_message; |
+ EXPECT_EQ(static_cast<int>(final_message.size()), |
+ client_->Send(final_message)); |
+ EXPECT_EQ_WAIT(expected, server_->GetReceivedData(), kTimeout); |
+} |
+ |
// Test transfer between client and server, using ECDSA |
TEST_F(SSLAdapterTestTLS_ECDSA, TestTLSTransfer) { |
TestHandshake(true); |